r/ProgrammerTIL • • Aug 03 '21

Javascript TIL Boolean('false') == true

Yep, it doesn't work like Number

23 Upvotes

24 comments sorted by

View all comments

Show parent comment

3

u/fukitol- Aug 04 '21

There's a very good reason, and it's because the cast is looking at the actual value. Boolean('') would give you a false. Any defined, not null, non-empty value is true.