NaN : Not A Number
NaN is known as Not A Number
It is a returned value
It is not configurable and not writable.
Example of NaN
When we will get output as NaN ?
<script>
var a = 'xyz';
document.write(a*2); // Output NaN
</script>
Not equal to itself
NaN is the only JavaScript value which is not equal to itself.
<script>
var a = NaN;
if(a === a){
document.write('Equal')
}else{
document.write('Not Equal')
}
</script>
The output will be Not Equal
To check the value is NaN, we can use isNaN →
User entered data from an input text box is always a string, so for any mathematical calculation we need to convert them to number by using parseFlot or parseInt. Otherwise we will get NaN as output of any mathematical calculation if we use directly these inputs.
String to Number by parseInt →
←JavaScript Math Reference
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
plus2net.com
Math Functions in JavaScript