化拓教育网
您的当前位置:首页ECMAScript中typeof的用法实例

ECMAScript中typeof的用法实例

来源:化拓教育网


本篇文章分享给大家的内容是关于ECMAScript 中typeof的用法实例,内容很详细,接下来我们就来看看具体的内容,希望可以帮助到有需要的朋友。

typeof 返回变量的类型字符串值 、其中包括 “object”、“number”、“string”、“undefined”、“boolean”、

1、在变量只声明、却不初始化值 Or 在变量没有声明时 返回 “undefined”

> > 'undefined'

> typeof e
'undefined'
>

2、所有引用对象,返回”object“

> a = > 'object'
> b = String("str"> 'object'
> c = Boolean(> 'object'
>
> var d = []
undefined
> typeof d
'object'
>
> var e = {}
undefined
> typeof e
'object'
>

3、根据变量值返回对应类型 “string”、“number”、“boolean”

> var a = 98undefined> typeof a'number'
> var b = 'aaa'undefined> typeof b'string'
> var c = trueundefined> typeof c'boolean'
>

相关推荐:

JavaScript学习中常会遇到的js事件处理程序

对Element UI table组件的源码的详细分析

显示全文