Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

11
  • Interesting technique... Commented Feb 13, 2012 at 20:12
  • 1
    "negating the result" is misleading, @Twisol's answer is more accurate Commented Feb 13, 2012 at 20:14
  • 1
    @Jonz -- Yes, it evaluates it before throwing it away, not like it's an expensive op. It also prevents errors from code that basically evaluates to: (function(){})()(function(){})() -- The lack of ; in the middle of that means the 2nd function is passed to the result of the first. Not desired behavior usually and results in an error or really weird behavior. ! or any binary op prevents this Commented Jul 12, 2013 at 7:38
  • 4
    @downeyt The ! does not have two meanings. When the JS runtime sees ! it knows that it can only mean (because there is only one meaning for !) logical negation and because of that, the JS runtime understands that you can only negate an expression, not a statement, so the remainder of the instruction is treated as such. In this usage, the result of the expression doesn't matter and is discarded. There is no dual-meaning. Commented Oct 8, 2017 at 15:26
  • 1
    Because it's the right thing to do :-) . It is never too late to put something straight. If he hadn't corrected it, I would have. Commented Aug 19, 2020 at 13:13