Using the typeof operator on a value may return one of the following strings:
"undefined" - if the value is undefined
"boolean" - if the value is a Boolean value
"string ” - if this value is a string
"number" - if this value is a numeric value
"object" - if this is an object or null
"function" - if this value is a function
The return values of commonly used typeof operators include number, string, boolean, undefined, object and function. For example:
These examples illustrate that the operand of the typeof operator can be a variable (message) or a numerical literal. Note that typeof is an operator, not a function, so the parentheses in the example are not necessary (although they can be used).
From the above example, we found that the number created with Number() will also be judged as an object by typeof and the value "object" will be returned. This is because the constructor returns all objects, so if we want to What to do when you want to distinguish JavaScript built-in objects such as Number, String, Array, Function, Date, Boolean and Error. Woolen cloth? Here you can call the toString method of the object, such as: