Search code examples
htmlevent-handlingaddeventlistenerweb-worker

What is the difference between "!window" and "!!window"?


I know my question is a bit vague but really like to know a bit more. Thanks in advance. Just need a good, quick and easy run down of this.


Solution

  • !window and !!window are both boolean values in JavaScript. The ! operator will first convert the expression to is boolean form (see this gist about Implicit Boolean Conversions in JavaScript).

    !window is the inverse of that, it evaluates to true if and only if the window variable is either undefined or is defined to a 'falsy' value.

    !!window is a variable that evaluates to true if and only if a window global variable is defined to a truthy value (false otherwise).