In the session, we will be looking into the below table of content.
TABLE OF CONTENT
- NaN
- parseInt(), parseFloat(), and Number()
6. NAN
From most of the explanations, you will hear that NaN means Not a Number but wait for a second... that's true, right? yes of course that's the meaning but ask yourself do you truly understand how this works?
NaN (technically, a string is not a NaN just because its not a number)
NaN is an error that occurs when you try to perform an action which is meant for numbers
For Example
let isNotNaN = 'You think this is [NAN] just because its a string?';//This is not a NaN
let str = "Javascript";
let num = 20;
str * num; //This is a NAN
So yeah we now understand NaN right ๐
7. parseInt(), parseFloat(),and Number().
parseInt()
this function is used to convert a number-string to an integer number.
For Example
let str = '30.8';
parseInt(str);//30
parseFloat()
this function is used to convert a number-string to a floating number.
For Example
let str = '30.8';
parseFloat(str);//30.8
Number
this function is a way of converting a number-string to an exact number representation.
For Example
let str1 = '30';
let str2 = '30.5'
Number(str1);//30
Number(str2);//30.5
Top comments (0)