Home >Web Front-end >JS Tutorial >Usage examples of typeof in ECMAScript

Usage examples of typeof in ECMAScript

不言
不言Original
2018-07-26 12:44:491780browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn