DEV Community

Cover image for Technical Issues In Javascript | NaN.3
Emmanuel Chikwendu Onah
Emmanuel Chikwendu Onah

Posted on • Updated on

Technical Issues In Javascript | NaN.3

In the session, we will be looking into the below table of content.

TABLE OF CONTENT

  1. NaN
  2. 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
Enter fullscreen mode Exit fullscreen mode

Alt Text
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 
Enter fullscreen mode Exit fullscreen mode

parseFloat()

this function is used to convert a number-string to a floating number.
For Example

let str = '30.8';
parseFloat(str);//30.8
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Previous Content

Top comments (0)