What does !! (double exclamation mark) mean in JavaScript?
Hi everyone! I just started learning JavaScript and came across a strange construct in someone else's code. It was something like:\n\n```javascript\nlet isActive = !!someValue;\n```\n\nI understand that one exclamation mark `!` is the logical "NOT" operator, which inverts the value (makes `true` from `false` and vice versa). But why write two exclamation marks in a row? Isn't that the same as just writing `!(!someValue)`? Or is it some special operator that I don't know about?\n\nI tried playing around in the browser console:\n\n```javascript\nconsole.log(!!"hello"); // true\nconsole.log(!!0); // false\nconsole.log(!!""); // false\nconsole.log(!!null); // false\nconsole.log(!!undefined); // false\nconsole.log(!!42); // true\n```\n\nThe results are somewhat
No answers yet.
Log in to leave an answer