How to evaluate this statement in javascript?
isnan = NaN;
notnan = "hello";
typeof(notnan) === "number" && isNaN(notnan);
How to evaluate this statement in javascript?
isnan = NaN;
notnan = "hello";
typeof(notnan) === "number" && isNaN(notnan);
This statment is illogical, because you're trying to see if it's a number and not a number in same statement, making two different booleans output.
typeof(notnan) === "number" && isNaN(notnan);
I believe you're looking for
if (!isNaN(notnan)) {
// Code if it's a number
} else {
// Code if it's not a number
}
IF you expect to flip it, you add !
to start it
!isNaN(notnan)
/*
* Returns opposite of isNaN, if it's a number then `true`
* else returns `false`.
*/
EDIT:
typeof(notnan) === "number" && isNaN(notnan);
Reason this doesn't work is because notnan is a string, therefore it returns false and doesn't evaluate properly. isNaN
alone works perfectly fine.
run this it will say something,
isnan = NaN;
notnan = "hello";
if (typeof(notnan) === "number" && isNaN(notnan)){
console.log('yes');
}
else {
console.log('typeof(notnan) is :',typeof(notnan), '\n isNaN(notnan) :', isNaN(notnan),'\n this is,',typeof(notnan)=== "number",'-',isNaN(notnan), 'so this condition became false...')
}