Home >Web Front-end >JS Tutorial >How to determine undefined in JS (a good method)_javascript skills

How to determine undefined in JS (a good method)_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:54:011163browse

I encountered a problem in a recent project. Let me share it with you.

After using servlet to assign the value to the text box of the HTML page, use alert to pop up the value. The result shows "undefined". So I naturally Use this value to compare with the string "undefined". Unfortunately, the comparison result is false.

There is no way, I can only google it and find a master.

It turns out that typeof must be used , the writing method is:

Copy the code The code is as follows:

if(typeof(value)== "undefined"){

alert("undefined");

}

This way "undefined" will pop up smoothly;

typeof returns a string, there are six possibilities: "number" "String" "boolean" "object" "function" "undefined"
Statement:
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