JavaScript you don't Know (middle)--ToBoolean
The values in JavaScript can be divided into the following two categories:
1. A value that can be coerced into a type that is False
2. Other (values that are cast to true for the coercion type)
false Values ---the following are the false values defined in the ES specification of JS:
- Undefined
- Null
- False
- +0,-0, and Nan
- ""-empty string
False value is the only coercion type conversion result is false. In general, except for the false value is the truth.
False Value Object -- an object that encapsulates a false value
eg
var a=new Boolean (false);
var b=new Boolean (0);
var c=new Boolean ("");
The "note" specification stipulates that " all objects are true", so even if the encapsulated contents are false values, these objects are still truth.
That is: Boolean (a&&b&&c) ==>true
"Note" In the JS code, the object is judged to be false, but it does not actually belong to the JavaScript language category. It's about the browser. In some cases, the browser wears some foreign values on the regular JS syntax, which is the "False value object".
eg
document.all, is a class array object that contains all the elements on the page, provided by the DOM (not provided by the JS engine) to the JS program.
The result of forcing type conversion on the browser with document.all can be used to determine if it is IE (old version), which may be hidden in the future because of the end of IE's support for document.all.
True value-values outside the list of false values
eg
var a= "false"; String False--true
var a= "0"; String 0--true
var a= "'"; String '--true
Boolean (a&&b&&c) ==>true. Note: Only the empty string is converted to false.
eg
var a=[]; Empty array--true
var b={}; Empty Object--true
var c=function () {}; Null function--true
Boolean (a&&b&&c) ==>true
JS in false value _es5 defined in the ToBoolean method force type conversion after the value is False