×

Index

JavaScript Tutorial

JavaScript Examples

CSS Tutorial

CSS Examples

undefined property with Example in JavaScript

JavaScript undefined property: Here, we are going to learn about the undefined property of JavaScript.
Submitted by IncludeHelp, on February 01, 2019

JavaScript undefined Property

If you have some of the variables and check whether their types are properly defined or assigned with a value (when we assign the value to the variable its type is defined). In that case, you can use undefined property. undefined property is used to check whether a variable is defined or not in the JavaScript.

Return value

It returns true - if a variable's type is defined or returns false - if a variable's type is not defined.

Example

<html>
<head>
<title>JavaScipt Example</title>
</head>

<body>
	<script>
		var a;
		var b =10;
		
		//checking variables are defined or not
		if(typeof a=="undefined")
			document.write("a is undefined");
		else
			document.write("a is defined");
		document.write("<br>");
		
		if(typeof b=="undefined")
			document.write("b is undefined");
		else
			document.write("b is defined");
		document.write("<br>");		
		
		//assigning value to a
		a = "Hello";

		if(typeof a=="undefined")
			document.write("a is undefined");
		else
			document.write("a is defined");
		document.write("<br>");		
		
	</script>
</body>
</html>

Output

a is undefined
b is defined
a is defined

JavaScript Built-in Functions »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.