Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript !!"false"

Tags:

javascript

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?

like image 833
mjmitche Avatar asked May 08 '26 22:05

mjmitche


2 Answers

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

like image 60
deceze Avatar answered May 11 '26 11:05

deceze


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

like image 43
Mike Lewis Avatar answered May 11 '26 10:05

Mike Lewis