Home > Article > Web Front-end > Usage examples of typeof in ECMAScript
The content shared with you in this article is about the usage examples of typeof in ECMAScript. The content is very detailed. Next, let’s take a look at the specific content. I hope it can help friends in need.
typeof returns the type string value of the variable, including "object", "number", "string", "undefined", "boolean",
1. When the variable is only declared, But does not initialize the value Or returns "undefined" when the variable is not declared
> > 'undefined' > typeof e 'undefined' >
2. All reference objects return "object"
> a = > 'object' > b = String("str"> 'object' > c = Boolean(> 'object' > > var d = [] undefined > typeof d 'object' > > var e = {} undefined > typeof e 'object' >
3. Return the corresponding type "string", "number", "boolean" according to the variable value
> var a = 98undefined> typeof a'number' > var b = 'aaa'undefined> typeof b'string' > var c = trueundefined> typeof c'boolean' >
Related recommendations:
js event handlers often encountered in JavaScript learning
Detailed analysis of the source code of the Element UI table component
The above is the detailed content of Usage examples of typeof in ECMAScript. For more information, please follow other related articles on the PHP Chinese website!