Truthy and Falsy in JavaScript introduction _ javascript tips-js tutorial

Source: Internet
Author: User
This article mainly introduces Truthy and Falsy in JavaScript, And the Truthy and Falsy values in JavaScript. This article describes related concepts, for more information, see the boolean Type in JavaScript, which is the same as that in most programming languages. However, unlike many other programming languages, JavaScript has the concept of Truthy and Falsy-all types of JavaScript values except boolean values true and false can be used for logical judgment, the rules are as follows:

1. All Falsy values are false when logical judgment is performed. Falsy values include: false, undefined, null, plus or minus 0, NaN, and ,"".
2. All other values are Truthy. true is used for logical judgment. It is worth noting that Infinity, an empty array, and "0" are all Truthy values.

Lab


The Code is as follows:


Var x = "0 ";
If (x ){
"String 0 is Truthy ."
} Else {
"String 0 is Falsy ."
}

Var y = [];
If (y ){
"Empty array is Truthy ."
} Else {
"Empty array is Falsy ."
}

Related Article

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.