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

来源:互联网 发布:seo教学 编辑:程序博客网 时间:2024/06/06 20:04

数据类型: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 ResultsType of valResultUndefined"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高级程序设计(第三版)》

阅读全文
0 0
原创粉丝点击