In the session, we will be looking into the below table of content.
- parseInt(), parseFloat(), and Number()
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 is an error that occurs when you try to perform an action which is meant for numbers
let isNotNaN = 'You think this is [NAN] just because its a string?';//This is not a NaN
this function is used to convert a number-string to an integer number.
let str = '30.8'; parseInt(str);//30
this function is used to convert a number-string to a floating number.
let str = '30.8'; parseFloat(str);//30.8
this function is a way of converting a number-string to an exact number representation.
let str1 = '30'; let str2 = '30.5' Number(str1);//30 Number(str2);//30.5