How to convert javascript string to Boolean

藏色散人
Release: 2021-11-18 15:46:37
Original
10413 people have browsed it

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
Copy after login

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();
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template