数据类型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
}
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
}