Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is 'false' truthy in javascript?

I understand that an empty string is falsy in javascript and a not-empty string is truthy in javascript.

However, why is 'false' truthy in javascript, is there anything explicit in the specification? Is it a performance issue or are there situations where you would want the string 'false' to represent true?

like image 859
StuperUser Avatar asked Nov 27 '22 16:11

StuperUser


1 Answers

is there anything explicit in the specification?

Yes:

The result is false if the argument is the empty String (its length is zero); otherwise the result is true.

like image 57
James Thorpe Avatar answered Dec 04 '22 01:12

James Thorpe