数据类型Boolean类型

来源:互联网 发布:示剑网络马大伟 编辑:程序博客网 时间:2024/06/06 03:45
数据类型Boolean类型:

var box="myDemo";//值显示真
if (box) {
    alert('真');
    // statement
} else {
    alert('假');
    // statement
}

var box="";//值显示假
if (box) {
    alert('真');
    // statement
} else {
    alert('假');
    // statement
}

var box=123;//值显示真
if (box) {
    alert('真');
    // statement
} else {
    alert('假');
    // statement
}

var box=-123;//值显示真
if (box) {
    alert('真');
    // statement
} else {
    alert('假');
    // statement
}

var box=0;//值显示假
if (box) {
    alert('真');
    // statement
} else {
    alert('假');
    // statement
}

var box=-NaN;//值显示假
if (box) {
    alert('真');
    // statement
} else {
    alert('假');
    // statement
}

var box={};//值显示真
if (box) {
    alert('真');
    // statement
} else {
    alert('假');
    // statement
}

var box=null;//值显示假
if (box) {
    alert('真');
    // statement
} else {
    alert('假');
    // statement
}

var box;//值显示假,因为数据类型为Undefined
if (box) {
    alert('真');
    // statement
} else {
    alert('假');
    // statement
}



0 0
原创粉丝点击