Home>Article>Web Front-end> How to determine whether it is null in javascript
Javascript method to determine whether it is null: 1. Determine through the "if (value === null) {...}" method; 2. Through "if (!value && typeof value !=" undefined"&&..." method to judge.
The operating environment of this article: Windows7 system, javascript version 1.8.5, Dell G3 computer.
Javascript determines whether it is null?
The Javascript script language, like other languages, has its own basic data types, expressions and arithmetic operators and the basic program framework of the program. Javascript provides There are four basic data types and two special data types used to process data and text. Variables provide a place to store information, and expressions can complete more complex information processing.
Judge whether it is Null method:
Method 1:
function isNull(value) { if (value === null) { return true; } else { return false; } }
=== Judgment rule
If the types are different, [not equal]
If both are numerical values, and they are the same value, then [equal]; (!Exception) is that if at least one of them is NaN, then [not equal]. (To determine whether a value is NaN, you can only use isNaN() to determine )
If both are strings and the characters at each position are the same, then [equal]; otherwise [not equal].
If both values are true, or both is false, then [equal].
If both values refer to the same object or function, then [equal]; otherwise [not equal].
If both values are null , or both are undefined, then [equal].
[Recommended video tutorial:js basic tutorial]
Method 2:
function isNull(value) { if (!value && typeof value != "undefined" && value != 0) { return true; } else { return false; } }
typeof exp != "undefined" excludes undefined;
exp != 0 excludes the number zero and false.
The above is the detailed content of How to determine whether it is null in javascript. For more information, please follow other related articles on the PHP Chinese website!