Reputation: 11
typeof(1) prints "Number" to the console, but when i ask if typeof(1) == Number, it prints out false, why ?
console.log(typeof(1));
//Number
console.log(typeof(1) == Number);
//false
Upvotes: 1
Views: 116
Reputation: 3605
typeof
returns a string , so check against one
typeof(1) == 'number' // true
// or better without ( ), since you don't need them here
typeof 1 == 'number' // true
and it should be fine.
More background info on typeof
: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof
Upvotes: 2