I have a question about type conversions. Given the following table from w3schools.com...
Why are the strings "0" and "000" converted to boolean true?
I have a question about type conversions. Given the following table from w3schools.com...
Why are the strings "0" and "000" converted to boolean true?
Because when you coerce a value to boolean in JavaScript, any non-blank string is true
. Only blank strings are false
.
The reason of it is because both "0" and "000" are strings and not numbers.
Any string which is non-empty converted to boolean is going to be true.