Home > Web Front-end > JS Tutorial > body text

Example of initial value of Boolean object in js_javascript skills

WBOY
Release: 2016-05-16 16:57:23
Original
1188 people have browsed it

Boolean (logical) objects are used to convert non-logical values ​​into logical values ​​(true or false).
Create a Boolean object

Use the keyword new to define a Boolean object. The following code defines a logical object named myBoolean:

var myBoolean=new Boolean()

Note: If the logical object has no initial value or its value is 0, -0, null , "", false, undefined or NaN, then the value of the object is false. Otherwise, its value is true (even when the argument is the string "false")!

All lines of code below create Boolean objects with an initial value of false.

Copy code The code is as follows:



Run result:

false
false
false
false
false
false

All the following lines of code will create a Boolean object with an initial value of true:
Copy the code The code is as follows:



Running results:

true
true
true
true
true
As for this initial value, it is different from that of java and c. Please pay attention when writing the front desk in the future!
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