Javascript method to convert a string to a Boolean value: 1. Create an HTML sample file; 2. Add a script tag; 3. Convert the string to A Boolean value is sufficient.
The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.
javascript How to convert string to Boolean?
js Convert string to Boolean value boolean
Boolean(); If the parameters are 0, null and no parameters, it returns false, and if there are parameters, it returns true.
Boolean(""); //输出为:false Boolean(null); //输出为:false Boolean(0); //输出为:false Boolean("hi"); //输出为:true Boolean(100); //输出为:true Boolean(new Object()); //输出为:true
Related introduction:
Creating a Boolean object
The Boolean object represents two values: "true" or "false"
The following code defines a Boolean object named myBoolean:
var myBoolean=new Boolean();
If the Boolean object has no initial value or its value is:
0
-0
null
""
false
undefined
NaN
Then the value of the object is false. Otherwise, its value is true (even when the variable value is the string "false")!
Recommended study: "javascript basic tutorial"
The above is the detailed content of How to convert javascript string to Boolean. For more information, please follow other related articles on the PHP Chinese website!