How to convert javascript string to Boolean
This article mainly introduces how to turn javascript strings into boolean, which has certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let Xiaobian take you to understand it together.
javascript The method of converting a string to a Boolean value: 1. Create an HTML sample file;2. Add a script tag;3. Convert a string to a Boolean value by "Boolean(" string ");".
Operating environment of this article: Windows 7 system, Javascript version 1.8.5, Dell G3 computer.
js converts string to boolean
Boolean(); 0, null and no arguments return false, with arguments return true.
Boolean("");//Output is: falseBoolean(null);//Output is: falseBoolean(0);//Output is: false Boolean("hi");//Output is: trueBoolean(100);//Output is: trueBoolean(new Object()); //Output is: true
Related Introduction:
Creating Boolean objects
Boolean objects represent 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")!
Thank you for reading this article carefully. I hope that the article "How to convert javascript strings to Boolean" shared by Xiaobian will be helpful to everyone. At the same time, I hope that everyone will support it more and pay attention to the industry information channel. More relevant knowledge is waiting for you to learn!