共用方式為


Boolean.parse Function

Converts a string representation of a logical value to its Boolean object equivalent. This function is static and can be invoked without creating an instance of the object.

var booleanVar = Boolean.parse("true");

Arguments

Term

Definition

value

A string representation of true or false.

Return Value

A Boolean value (true or false) that corresponds to the value argument.

Exceptions

Exception type

Condition

Error.argumentOutOfRange Function

(Debug) value does not contain a string representation of true or false.

Remarks

Use the parse function to create a Boolean value from a string representation. The value argument must be "true" or "false" (case insensitive). The string can contain white space. If the string cannot be converted to a Boolean value, an exception is thrown.

Example

The following example shows how to use the parse function to create a Boolean value from a string.

var a = new Boolean(true);      
if (a == true){
    alert("a = true"); 
}else{
    alert("a = false");
}

var b = Boolean.parse("true");
if (b == true){
    alert("b = true"); 
}else{
    alert("b = false");
}

See Also

Reference

Boolean Type Extensions

Boolean Object

boolean Data Type (Visual Studio - JScript)

Other Resources

Language Reference