I found that to test if a variable is a number you can do:
!isNaN()
or
typeof () === "number"
Yet, when the character is an empty space " " or even a string with nothing “”, the !isNaN()
method fails:
let x = 3;
console.log(!isNaN(x));
console.log(typeof x === "number");
// true
// true
let y = " ";
console.log(!isNaN(y));
console.log(typeof y === "number");
// true
// false
let y = "";
console.log(!isNaN(y));
console.log(typeof y === "number");
// true
// false
Why is this?