Originally, I thought that the Boolean conversion of js was the same as that of java. After all, we all have the same ancestor. Here is how I wrote it.
function foo() {
var temp = Boolean.valueOf('');
alert(temp == false);
}
java variable javaBoolean is a string , its value is "false". Originally, I thought it would definitely output true, but the result is false, which is really frustrating.
I just checked "The Definitive Guide to JavaScript" and I suddenly had an idea. It turns out to be like this:
If you want to convert other types to Boolean, you should use Boolean(value) or new Boolean(value). The Boolean.valueOf() method is unique to objects and is not a static method of Boolean. method, there is another important point: 0, NaN, null, empty string and undefined will be converted to false, and other primitive values, except false (but containing the string "false"), as well as other objects and arrays will be converted is true.
Seeing this, you should think that being fooled by js is worth it, right?