1)
Boolean expressionAn expression that evaluates to either true or false. Non-Boolean expressions are converted to Boolean values, when necessary, according to the following rules: All objects are considered true.
Strings are considered false if and only if they are empty.
null and undefined are considered false.
Numbers are considered false if and only if they are zero. 2)
As JScript is loosely typed, a single variable can hold different types of data over the course of a script.
Boolean expressionAn expression that evaluates to either true or false. Non-Boolean expressions are converted to Boolean values, when necessary, according to the following rules: All objects are considered true.
Strings are considered false if and only if they are empty.
null and undefined are considered false.
Numbers are considered false if and only if they are zero. 2)
As JScript is loosely typed, a single variable can hold different types of data over the course of a script.
}也是用typeof(var)
Returns a string that identifies the data type of an expression.typeof[(]expression[)] ;The expression argument is any expression for which type information is sought. Res
The typeof operator returns type information as a string. There are six possible values that typeof returns: "number," "string," "boolean," "object," "function," and "undefined."
<script>
var abc=false;
if(abc){
}
alert()
</script>
判断是否被声明:
if(typeOf(a) == "undefined") {
alert("未定义");
}使用typeOf(变量名)可以获得变量的类型。
var abc;
function test(name){
try{eval(name);return true}catch(e){return false};
}
alert(test("abc"))
alert(test("def"))
</script>
{
alert("error:");
}
typeof 不是 typeOf