Amirreza
Amirreza

Reputation: 1

Why the output of this code is false? please answer me

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

Answers (2)

Semnodime
Semnodime

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

Flynn FC
Flynn FC

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

Related Questions