ds-algo-study
Version:
Just experimenting with publishing a package
87 lines (77 loc) • 4.1 kB
HTML
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="./../../../assets/style.css" />
<link rel="stylesheet" href="./../../../assets/prism.css" />
<script async src="./../../../assets/prism.js"></script>
</head>
<body>
<blockquote>
<p>The Boolean() constructor is used to create Boolean objects.</p>
</blockquote>
<h2 id="syntax">Syntax</h2>
<p>new Boolean([value])</p>
<h3 id="parameters">Parameters</h3>
<p><code>value</code> Optional</p>
<p>The initial value of the <code>Boolean</code> object.</p>
<h3 id="creating-boolean-objects-with-an-initial-value-of-false">Creating <code>Boolean</code> objects with an initial
value of <code>false</code></h3>
<pre data-role="codeBlock" data-info="js" class="language-javascript"><code>let bNoParam = new Boolean();
let bZero = new Boolean(0);
let bNull = new Boolean(null);
let bEmptyString = new Boolean('');
let bfalse = new Boolean(false);</code></pre>
<h3 id="creating-boolean-objects-with-an-initial-value-of-true">Creating <code>Boolean</code> objects with an initial
value of <code>true</code></h3>
<pre data-role="codeBlock" data-info="js" class="language-javascript"><code>let btrue = new Boolean(true);
let btrueString = new Boolean('true');
let bfalseString = new Boolean('false');
let bSuLin = new Boolean('Su Lin');
let bArrayProto = new Boolean([]);
let bObjProto = new Boolean({});</code></pre>
<h1 id="array.prototype.every">Array.prototype.every()</h1>
<blockquote>
<p>The every() method tests whether all elements in the array pass the test implemented by the provided function. It
returns a Boolean value.</p>
</blockquote>
<p>The <strong><code>every()</code></strong> method tests whether all elements in the array pass the test implemented
by the provided function. It returns a Boolean value.</p>
<h2 id="syntax-1">Syntax</h2>
<p>arr.every(callback(element[, index[, array]])[, thisArg])</p>
<h3 id="parameters-1">Parameters</h3>
<p><code>callback</code></p>
<p>A function to test for each element, taking three arguments:</p>
<p><code>element</code></p>
<p>The current element being processed in the array.</p>
<p><code>index</code> Optional</p>
<p>The index of the current element being processed in the array.</p>
<p><code>array</code> Optional</p>
<p>The array <code>every</code> was called upon.</p>
<p><code>thisArg</code> Optional</p>
<p>A value to use as <code>this</code> when executing <code>callback</code>.</p>
<h3 id="return-value">Return value</h3>
<p><strong><code>true</code></strong> if the <code>callback</code> function returns a [truthy]</p>
<p>value for all elements, <code>every</code> returns <code>true</code>.</p>
<p><strong>Caution</strong>: Calling this method on an empty array will return <code>true</code> for any condition!
</p>
<p><code>callback</code> is invoked only for array indexes which have assigned values. It is not invoked for indexes
which have been deleted, or which have never been assigned values.</p>
<p><code>callback</code> is invoked with three arguments: the value of the element, the index of the element, and the
Array object being traversed.</p>
<p>If a <code>thisArg</code> parameter is provided to <code>every</code>, it will be used as callback's
<code>this</code> value. Otherwise, the value <code>undefined</code> will be used as its <code>this</code> value.
The
<code>this</code> value ultimately observable by <code>callback</code> is determined according to <a class="btn"
href="chrome-extension://cjedbglnccaioiolemnfhjncicchinao/en-US/docs/Web/JavaScript/Reference/Operators/this">the
usual rules for determining the <code>this</code> seen by a function</a>.
</p>
<p><code>every</code> acts like the "for all" quantifier in mathematics. In particular, for an empty array, it returns
<code>true</code>.
</p>
</body>
</html>
</body>
</html>