Javascript的学习

typeof操作符:查看变量的数据类型

1.Undefined类型

var box;

alert(box);     //box是Undefined类型,值为undefined,返回的字符串是undefined;

Undefined类型只有一个值,就是undefined

2.Null类型

var box=null;

alert(box);     //box是Null类型,值为null,返回的字符串是object

undefined是派生自null,他们的比较的结果为true;

3.Boolean类型

var box=true;

alert(box);     //box是Boolean类型,值为true,返回的字符串是boolean

javascript中的数据类型都可以转换为Boolean类型

显示转换(强制性转换)

var box=250;

var box1=Boolean(250);

隐示转换

数据类型 转换为true值 转换为false值
Boolean true false
String 任何非空字符 空字符
Number 任何非0数字 0和NaN
Object 任何对象 null
Undefined   undefined

4.Number类型

var box=250;

alert(box);     //box是Number类型,值为250,返回的字符串是number

5.String类型

var box='kobe'

alert(box);     //box是String类型,值为kobe,返回的字符串是string

6.Object类型

var box={};   或者   var box=new Object();

alert(box);              //box是Object类型,值为object Object,返回的字符串是object

7.Function函数

var box=function

{}

alert(box);          //box是Function函数,值为function(){};,返回的字符串是function

原文地址:https://www.cnblogs.com/zouxiaofan/p/6426044.html