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

Usage examples of typeof in ECMAScript

不言
Release: 2018-07-26 12:44:49
Original
1759 people have browsed it

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'
>
Copy after login

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'
>
Copy after login

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'
>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template