JS in false value _es5 defined in the ToBoolean method force type conversion after the value is False

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.