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

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

WBOY
Release: 2016-05-16 16:54:01
Original
1132 people have browsed it

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"
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