2

I expected !!"false" to return false i.e. !"false" would return true, so !!"false" would return "false", but when I tested it in the console, !!"false" returned true.

Why didn`t things happen as expected?

mjmitche
  • 2,077
  • 5
  • 24
  • 31
  • Possible duplicate of [How can I convert a string to boolean in JavaScript?](http://stackoverflow.com/q/263965/125382). Voted to close. – MAK Mar 18 '11 at 04:42

2 Answers2

12

"false" is a non-empty string, which evaluates to true. Hence !"false" is false and !!"false" is true. You were probably thinking of !!false.

deceze
  • 510,633
  • 85
  • 743
  • 889
2

The reason this is occurring because anything other than an empty string will return true.

Mike Lewis
  • 63,433
  • 20
  • 141
  • 111