Home » JavaScript

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

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.

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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.