Home >Web Front-end >Front-end Q&A >How to convert javascript string to Boolean

How to convert javascript string to Boolean

藏色散人
藏色散人Original
2021-11-18 15:46:3710438browse

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.

How to convert javascript string to Boolean

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn