JavaScript | undefined Property
This property is used to check if a value is assigned to a variable or not.
Syntax:
var x;
if (typeof x === "undefined") {
txt = "x is undefined";
} else {
txt = "x is defined";
}
Return Value: It returns ‘defined’ if the variable is assigned any value and ‘undefined’ if the variable is not assigned any value.
Example:
<!DOCTYPE html> <html> <body> <center> <h1 style="color: green"> Geeks </h1> <button onclick="test()"> Press </button> <h4> Click on the Press button to check if "a" is defined or undefined. </h4> <p id="gfg"></p> <script> function test() { if (typeof a === "undefined") { txt = "'a' is undefined"; } else { txt = "'a' is defined"; } document.getElementById( "gfg").innerHTML = txt; } </script> </center> </body> </html> |
chevron_right
filter_none
Output:
Before clicking on the button:

After clicking on the button:

Browser Support: The listed browsers support JavaScript Undefined Property-
- Google Chrome
- Firefox
- Internet Explorer
- Opera
- Safari
Recommended Posts:
- variable === undefined vs. typeof variable === “undefined” in JavaScript
- What are undeclared and undefined variables in JavaScript?
- How to check empty/undefined/null string in JavaScript?
- How to remove error Call to undefined function curl_init()?
- JavaScript | multiline Property
- JavaScript | global Property
- JavaScript | source Property
- JavaScript | Math.LN2 property
- JavaScript | lastIndex Property
- How to remove CSS property using JavaScript?
- JavaScript | Cursor property
- JavaScript | Infinity Property
- JavaScript | Error name Property
- JavaScript | Math.PI Property
- Javascript | MouseEvent which Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



