Home > php教程 > PHP开发 > Understanding boolean types in javascript

Understanding boolean types in javascript

黄舟
Release: 2016-12-15 10:32:53
Original
1405 people have browsed it

Speaking of the Boolean type, I believe anyone who has had programming experience knows what it is. But the Boolean type in Javascript is very interesting.

 First of all, it is used to determine whether it is true or false, not just true or false. , it seems that any object can be used as a Boolean judgment. Do you have a sense of accomplishment that "everything in the world is for my use"? I checked it online and copied it from elsewhere and summarized it as follows:

 1. All objects are considered is true.

 2. A string is considered false if and only if it is empty ("" or '').

 3. Null and undefined are considered false.

 4. A number is false if and only if it is 0.

 So it is very convenient to use. If you want to judge whether there is an object on the page, just use this sentence:

if(button)
{
 alert("exist");
}
else
{
 alert("SORR\, does not exist");
}

Isn't it very convenient? Using this well can reduce a lot of code for judgment in javascript.

The above is the management of Boolean type content in javascript. For more related articles, please Follow the PHP Chinese website (m.sbmmt.com)!


Related labels:
source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template