Boolean.html 5.13 KB
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js"><span id='Boolean'>/**
</span> * @class Boolean
 *
 * The `Boolean` object is an object wrapper for a boolean value.
 *
 * The value passed as the first parameter is converted to a boolean value, if necessary. If value is
 * omitted or is 0, -0, null, false, `NaN`, undefined, or the empty string (&quot;&quot;), the object has an
 * initial value of false. All other values, including any object or the string `&quot;false&quot;`, create an
 * object with an initial value of true.
 *
 * Do not confuse the primitive Boolean values true and false with the true and false values of the
 * Boolean object.
 *
 * Any object whose value is not `undefined` or `null`, including a Boolean object whose value is false,
 * evaluates to true when passed to a conditional statement. For example, the condition in the following
 * if statement evaluates to true:
 *
 *     x = new Boolean(false);
 *     if (x) {
 *         // . . . this code is executed
 *     }
 *
 * This behavior does not apply to Boolean primitives. For example, the condition in the following if
 * statement evaluates to `false`:
 *     x = false;
 *     if (x) {
 *         // . . . this code is not executed
 *     }
 *
 * Do not use a `Boolean` object to convert a non-boolean value to a boolean value. Instead, use Boolean
 * as a function to perform this task:
 *
 *     x = Boolean(expression);     // preferred
 *     x = new Boolean(expression); // don't use
 *
 * If you specify any object, including a Boolean object whose value is false, as the initial value of a
 * Boolean object, the new Boolean object has a value of true.
 *
 *     myFalse = new Boolean(false);   // initial value of false
 *     g = new Boolean(myFalse);       // initial value of true
 *     myString = new String(&quot;Hello&quot;); // string object
 *     s = new Boolean(myString);      // initial value of true
 *
 * Do not use a Boolean object in place of a Boolean primitive.
 *
 * # Creating Boolean objects with an initial value of false
 *
 *     bNoParam = new Boolean();
 *     bZero = new Boolean(0);
 *     bNull = new Boolean(null);
 *     bEmptyString = new Boolean(&quot;&quot;);
 *     bfalse = new Boolean(false);
 *
 * # Creating Boolean objects with an initial value of true
 *
 *     btrue = new Boolean(true);
 *     btrueString = new Boolean(&quot;true&quot;);
 *     bfalseString = new Boolean(&quot;false&quot;);
 *     bSuLin = new Boolean(&quot;Su Lin&quot;);
 *
 * &lt;div class=&quot;notice&quot;&gt;
 * Documentation for this class comes from &lt;a href=&quot;https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Boolean&quot;&gt;MDN&lt;/a&gt;
 * and is available under &lt;a href=&quot;http://creativecommons.org/licenses/by-sa/2.0/&quot;&gt;Creative Commons: Attribution-Sharealike license&lt;/a&gt;.
 * &lt;/div&gt;
 */

<span id='Boolean-method-constructor'>/**
</span> * @method constructor
 * Creates a new boolean object.
 * @param {Object} value Either a truthy or falsy value to create the corresponding Boolean object.
 */

//Methods

<span id='Boolean-method-toString'>/**
</span> * @method toString
 * Returns a string of either &quot;true&quot; or &quot;false&quot; depending upon the value of the object.
 * Overrides the `Object.prototype.toString` method.
 *
 * The Boolean object overrides the `toString` method of the `Object` object; it does not inherit
 * `Object.toString`. For Boolean objects, the `toString` method returns a string representation of
 * the object.
 *
 * JavaScript calls the `toString` method automatically when a Boolean is to be represented as a text
 * value or when a Boolean is referred to in a string concatenation.
 *
 * For Boolean objects and values, the built-in `toString` method returns the string `&quot;true&quot;` or
 * `&quot;false&quot;` depending on the value of the boolean object. In the following code, `flag.toString`
 * returns `&quot;true&quot;`.
 *
 *     var flag = new Boolean(true)
 *     var myVar = flag.toString()
 *
 * @return {String} The boolean value represented as a string.
 */

<span id='Boolean-method-valueOf'>/**
</span> * @method valueOf
 * Returns the primitive value of the `Boolean` object. Overrides the `Object.prototype.valueOf` method.
 *
 * The `valueOf` method of Boolean returns the primitive value of a Boolean object or literal Boolean
 * as a Boolean data type.
 *
 * This method is usually called internally by JavaScript and not explicitly in code.
 *
 *     x = new Boolean();
 *     myVar = x.valueOf()      //assigns false to myVar
 *
 * @return {Boolean} The primitive value.
 */</pre>
</body>
</html>