-1

This really confuses me. I'm checking for an IE 10+ browser and everything online says use (!!document.documentMode == true ), but why not (document.documentMode == false )? How are they not the same? Are we saying in the first the document.documentMode is missing and not false but null?

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Sherpa11
  • 153
  • 1
  • 1
  • 14
  • 1
    `!` reverses the boolean sense, while `!!` basically is `Boolean(something)`. They're opposites. – Pointy Apr 28 '21 at 18:52
  • The `!!` forces the value to be a boolean without negating it. It's a double negative. One `!` casts the value to a boolean in order to negate it, and the second `!` negates it again, giving you the original value cast to a boolean. – ray Apr 28 '21 at 18:54
  • Does this answer your question? [What is the !! (not not) operator in JavaScript?](https://stackoverflow.com/questions/784929/what-is-the-not-not-operator-in-javascript) – Heretic Monkey Apr 28 '21 at 18:56

2 Answers2

1

! forces the value to convert to that opposite truthy boolean. !! does that twice, meaning it forces it to convert to the same truthy boolean.

false => false
!false => true
!!false => false

Therefor

!!<Falsy value> => false
!!<Falsy value> == true => false
Cody E
  • 179
  • 11
0

Because undefined is not equal than false.

However, if you use Boolean in your document.documentMode it will evaluate it to true

Boolean(document.documentMode) == false

Because undefined is a falsy value

more info here.