Home > Web Front-end > JS Tutorial > body text

JS 判断undefined的实现代码_javascript技巧

WBOY
Release: 2016-05-16 18:41:06
Original
927 people have browsed it

以下是不正确的用法:

复制代码 代码如下:

var exp = undefined;
if (exp == undefined)
{
alert("undefined");
}

exp 为 null 时,也会得到与 undefined 相同的结果,虽然 null 和 undefined 不一样。
以下是正确的用法:
复制代码 代码如下:

var exp = undefined;
if (typeof(exp) == "undefined")
{
alert("undefined");
}

typeof 返回的是字符串,有六种可能:"number"、"string"、"boolean"、"object"、"function"、"undefined"
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!