Hacker News new | ask | show | jobs
by dandare 1956 days ago
Tangential question, what does the !! operator do in:

  const supported = !! self.WebAssembly;
3 comments

It's just the not "!" operator twice.

The first NOT operator (from right to left) casts the following operand to the boolean primitve type and negates the value.

The second NOT operator reverses the truth value of the boolean, in order to regain the original truthiness.

!self.WebAssembly; -> false if self.WebAssembly is truthy (eg. object exists), true otherwise

!!self.WebAssembly; = !(!self.WebAssembly;) = !(false|true) -> true if WebAssembly is defined, false otherwise.

coerces the object to a boolean
Of course! :)
! Is the operator but it is used twice.