Reputation: 1
let number = 5;
console.log(typeof number !== "number")
I do not understand why a variable with a number type is equal to a string
Upvotes: 0
Views: 45
Reputation: 2003
I do not understand why a variable with a number type is equal to a string
It's not the variable that is equal to a string, instead it is the type that is (equal to) a string!
The type of the variable 5
is "number"
(as determined by typeof number
) and "number"
is a string.
Upvotes: 0
Reputation: 11
because the type of number (in this case 5) is "number".
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof
Upvotes: 1