I was trying to make an isNaN() function that checks the user's input if its a NaN or not, but it always skips the the first condition whatever the user's input is.
function isNaN() {
let value = prompt("enter value");
if (typeof value === "number") {
console.log("value is number");
}else {
console.log("NaN");
}
} isNaN();
I made the program to checks the user's input data type by typeof operator.
prompt()always returns a string ornull. Even if the string looks numeric, the type is stillstring.parseFloat()to try to convert the input to a number. It will returnNaNif it can't parse it.isNaN()implementation, intentionally or not, is not a good idea.console.log(typeof value)to see why the condition isn't working as expected? ericlippert.com/2014/03/05/how-to-debug-small-programs