Suggest an editImprove this articleRefine the answer for “The ! operator”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**The `!` operator** is **logical NOT**, which **inverts** the logical value of an expression. **Key point:** Double negation `!!value` is a short way to explicitly coerce any value to the `boolean` type.Shown above the full answer for quick recall.Answer (EN)ImageThe `!` operator is called **logical negation (NOT)**. It **inverts** (flips) the logical value of an expression. --- ### Rule: ```javascript !true → false !false → true ``` > If a value is **truthy** - it becomes `false`. > If it is **falsy** - it becomes `true`. --- ## Examples of using `!` ```javascript !true // false !false // true !0 // true (0 - a falsy value) !1 // false (1 - truthy) !"" // true (an empty string - falsy) !"hello" // false (a non-empty string - truthy) !undefined // true !null // true !NaN // true ![] // false (an array - truthy) !{} // false (an object - truthy) ``` --- ## Double negation `!!` A double operator is very common in JavaScript: ```javascript !!value ``` It is used to **coerce any value to the** `boolean` **type**. ### Example: ```javascript !!'hello' // true !!'' // false !!0 // false !!123 // true !!null // false !!{} // true !![] // true ``` > `!!` is a short and clear way to explicitly say: > "Convert this value to boolean". --- ## In logical expressions `!` is often used to check conditions: ```javascript const isLoggedIn = false; if (!isLoggedIn) { console.log('User is not authenticated'); } ``` > Here, `!isLoggedIn` → `!false` → `true`, > so the `if` block will execute. --- ## How it works internally 1. JS **first coerces the value to a logical type** (`true` / `false`); 2. then it **inverts** it. Example: ```javascript !'text' // step 1: 'text' → true; step 2: !true → false ``` --- ## Comparison with other logical operators | Operator | Name | Example | Result | |---|---|---|---| | `!` | Logical **NOT** | `!true` | `false` | | `&&` | Logical **AND** | `true && false` | `false` | | `\|\|` | `Logical OR` | `true \|\| false` | `true` | --- ## Summary | Situation | What `!` does | Example | |---|---|---| | Negates a logical value | `!true → false` | | | Coerces a value to `boolean` | `!!'js' → true` | | | Used in conditions | `if (!user)` → "if user is not set" | |For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.