您的位置:首页 > Web前端 > JavaScript

数据类型:如何判断类型——JavaScript知识小结04

2017-07-04 23:41 771 查看
数据类型:Undefined, Null, Boolean, String,
Symbol, Number,  Object.
typeof操作符

typeof 可能返回的值:undefined boolean string symbol number object(对象或者null)function 
查看数据类型操作符(不是函数),故使用是否括号皆可,返回的结果第一个字母小写。'typeof'的'o'是小写

typeof null;//object

虽然函数也是一种对象,不是一种数据类型,但是函数有其特殊属性,因此将其与其它对象区分。

var message = null;
typeof message;//object
typeof (95);//number

typeof Operator Results
Type of valResult
Undefined
"undefined"
Null
"object"
Boolean
"boolean"
Number
"number"
String
"string"
Symbol
"symbol"
Object (ordinary and does not implement [[Call]])
"object"
Object (standard exotic and does not implement [[Call]])
"object"
Object (implements [[Call]])
"function"
Object (non-standard exotic and does not implement [[Call]])Implementation-defined. Must not be 
"undefined"
"boolean"
"function"
"number"
"symbol"
,
or 
"string"
.
NOTE

Implementations are discouraged from defining new 
typeof
 result values for non-standard exotic objects. If possible 
"object"
 should
be used for such objects.

参考资料:ECMA标准:http://www.ecma-international.org/ecma-262/7.0/index.html#prod-Keyword
               《JavaScript高级程序设计(第三版)》
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  JavaScript 数据类型