Home » JavaScript

NaN property with example in JavaScript

JavaScript NaN property: Here, we are going to learn about the NaN property with the example in JavaScript.
Submitted by IncludeHelp, on February 02, 2019

NaN property

"NaN" stands for "Not-a-Number"; it is a global property in JavaScript which is used for the number which is not a legal i.e. it indicates that the value is not a legal number.

Example:

In this example, we have two variables, num1 which is assigned by 10 which is a legal number and num2 is assigned by parsing the value of "Hello" as an integer it returns an illegal number.

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

<body>
	<script>
		var num1 = 10;
		var num2 = parseInt("Hello");
		
		//printing the values
		document.write("num1: " + num1 + "<br>");
		document.write("num2: " + num2 + "<br>");		
	</script>
</body>
</html>

Output

num1: 10
num2: NaN





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.