Home > Web Front-end > JS Tutorial > A daily javascript learning summary (Boolean object)_javascript skills

A daily javascript learning summary (Boolean object)_javascript skills

WBOY
Release: 2016-05-16 15:32:37
Original
1202 people have browsed it

Syntax for creating Boolean objects:
new Boolean(value); //Constructor
Boolean(value); //Conversion function
Parameter value The value stored by a Boolean object or the value to be converted into a Boolean value.
Return value
When called as a constructor (with operator new), Boolean() will convert its argument to a Boolean value and return a Boolean object containing the value.
If called as a function (without operator new), Boolean() will simply convert its argument to a primitive Boolean value and return this value.
Note: If the value parameter is omitted, or is set to 0, -0, null, "", false, undefined, or NaN, the object is set to false. Otherwise set to true (even if the value argument is the string "false").

  var falseObject = new Boolean(false);
  var result = falseObject && true;
  alert(result); //true

  var falseValue = false;
  result = falseValue && true;
  alert(result); //false
  
  alert(typeof falseObject); //object
  alert(typeof falseValue); //boolean
  alert(falseObject instanceof Boolean); //true
  alert(falseValue instanceof Boolean); //false

Copy after login

Boolean object description
In JavaScript, Boolean values ​​are a basic data type. A Boolean object is a Boolean object that packs a Boolean value. Boolean objects are mainly used to provide the toString() method that converts Boolean values ​​into strings.
When the toString() method is called to convert a Boolean value to a string (usually called implicitly by JavaScript), JavaScript will internally convert the Boolean value into a temporary Boolean object and then call the toString() method of this object. .

The above is today’s summary of JavaScript learning, and it will continue to be updated every day. I hope you will continue to pay attention.

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