Home > Web Front-end > JS Tutorial > Introduction to Truthy and Falsy in JavaScript_javascript skills

Introduction to Truthy and Falsy in JavaScript_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 16:22:45
Original
1014 people have browsed it

Like most programming languages, there is a boolean type in JavaScript for logical judgment. However, unlike many other programming languages, JavaScript has the concepts of Truthy values ​​and Falsy values ​​- except for the boolean values ​​true and false, all types of JavaScript values ​​can be used for logical judgments. The rules are as follows:

1. All Falsy values ​​are false when making logical judgments. Falsy values ​​include: false, undefined, null, positive and negative 0, NaN, "".
2. All other values ​​are Truthy and are true when logical judgment is made. It is worth noting that Infinity, empty array, and "0" are all Truthy values.

Experiment


Copy code 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 labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template