+ 9

NaN in JavaScript confused me

var num = 8 * undefined console.log(num)// output NaN console.log(typeof(num))// output number // NaN means not number // so how can be the typeof NaN number?

4th Apr 2019, 6:35 AM
Khalid Issa Talaf Ibrahim
Khalid Issa Talaf Ibrahim - avatar
12 Respostas
+ 11
NaN is Not A Number. if you want to do any operation that result will not a number this time you get out put NaN. Look, if you want to do arithmetic operation with number and string it not possible. the outupt is NaN. To better observation, try this "100" - "10" //90 above this is string but do arithmetic operation. Now is it clear?!!
4th Apr 2019, 7:19 AM
Ahad
Ahad - avatar
+ 8
Welcome bro.🙂
4th Apr 2019, 7:24 AM
Ahad
Ahad - avatar
+ 5
NaN is typeof number because it is the result of a calculation that couldnt be calculated. I think NaN is defined in the number object and therefore type of NaN
4th Apr 2019, 7:00 AM
Dragonxiv
Dragonxiv - avatar
+ 5
thank you now i got it
4th Apr 2019, 7:22 AM
Khalid Issa Talaf Ibrahim
Khalid Issa Talaf Ibrahim - avatar
+ 4
plz tell what does mean NaN
4th Apr 2019, 7:16 AM
Khalid Issa Talaf Ibrahim
Khalid Issa Talaf Ibrahim - avatar
+ 4
NaN is the result of mixing non-numbers is math equations. If the variable is still of the type Number you should use isNaN() to test for your case.
5th Apr 2019, 6:53 AM
Maher F
Maher F - avatar
+ 4
The NaN property represents "Not-a-Number" value. This property indicates that a value is not a legal number. The NaN property is the same as the Number. Nan property. Tip: Use the isNaN() global function to check if a value is a NaN value.
5th Apr 2019, 10:38 AM
Dhara Paghadar
Dhara Paghadar - avatar
+ 3
Not a Number
4th Apr 2019, 7:19 AM
Dragonxiv
Dragonxiv - avatar
+ 3
Nan is Not a Number, if u calculate a number and string, the output is NaN
5th Apr 2019, 12:20 AM
Xander
Xander - avatar
+ 3
thank you Maher F it helpfull info
5th Apr 2019, 7:21 AM
Khalid Issa Talaf Ibrahim
Khalid Issa Talaf Ibrahim - avatar
+ 3
thank you for answer Dhara Paghadar
13th Apr 2019, 12:29 PM
Khalid Issa Talaf Ibrahim
Khalid Issa Talaf Ibrahim - avatar
+ 1
NaN is a property of the global object that represents "Not-a-Number" value. This property indicates that a value is not a legal number. it is rather rare to use NaN in a program directly like so: var notANumber = NaN; I think NaN is designed to check for valid user inputs or function parameters. for instance: if(isNaN(usrInput)) { doSomthingWith(usrInput); } or function doSomthingWith(x) { x = (isNaN(x)) ? 0 : x;//set x to 0 if the value of x is NaN }
12th Jun 2019, 11:32 AM
sanusi
sanusi - avatar