首页 > 设计 > WEB开发 > 正文

JS基础---typeof及数据类型总结

2019-11-02 18:24:46
字体:
来源:转载
供稿:网友

typeof---用于检测数据类型

undefined---未定义

boolean--布尔值

string--字符串

number--数字

object--对象或null

function--函数

typeof null返回值为object,特殊值null被认为是一个空对象的引用。

Undefined类型

Undefined类型只有一个值,即特殊的undefined。在使用var声明变量但未对其加以初始化时,这个变量的值就是undefined

eg: var test;alert(test==undefined);//true

注意,包含undefined值的变量与尚未定义的变量是不一样的。

eg:var test;//这个变量声明后默认取得了undefined值

        alert(test);//undefined

        alert(age);//产生错误

但是当对两者使用typeof操作符时,均返回undefined值


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表