Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If by JavaScript you also include versions newer than version 1.5, then you could also see the following:</p> <hr> <p><strong>Expression closures:</strong></p> <p>JavaScript 1.7 and older:</p> <pre><code>var square = function(x) { return x * x; } </code></pre> <p>JavaScript 1.8 added a shorthand <a href="http://en.wikipedia.org/wiki/Lambda_calculus#Lambda_calculus_and_programming_languages">Lambda notation</a> for writing simple functions with <a href="https://developer.mozilla.org/en/JavaScript/New_in_JavaScript/1.8#Expression_closures_%28Merge_into_own_page.2fsection%29">expression closures</a>:</p> <pre><code>var square = function(x) x * x; </code></pre> <hr> <p><strong>reduce() method:</strong></p> <p>JavaScript 1.8 also introduces the <a href="https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Global_Objects/Array/Reduce">reduce()</a> method to Arrays:</p> <pre><code>var total = [0, 1, 2, 3].reduce(function(a, b){ return a + b; }); // total == 6 </code></pre> <hr> <p><strong>Destructuring assignment:</strong></p> <p>In JavaScript 1.7, you can use the <a href="https://developer.mozilla.org/en/New_in_JavaScript_1.7#Destructuring_assignment_%28Merge_into_own_page.2fsection%29">destructuring assignment</a>, for example, to swap values avoiding temporary variables:</p> <pre><code>var a = 1; var b = 3; [a, b] = [b, a]; </code></pre> <hr> <p><strong>Array Comprehensions and the filter() method:</strong> </p> <p><a href="https://developer.mozilla.org/en/JavaScript/Guide/Predefined_Core_Objects#Array_comprehensions">Array Comprehensions</a> were introduced in JavaScript 1.7 which can reduce the following code:</p> <pre><code>var numbers = [1, 2, 3, 21, 22, 30]; var evens = []; for (var i = 0; i &lt; numbers.length; i++) { if (numbers[i] % 2 === 0) { evens.push(numbers[i]); } } </code></pre> <p>To something like this:</p> <pre><code>var numbers = [1, 2, 3, 21, 22, 30]; var evens = [i for each(i in numbers) if (i % 2 === 0)]; </code></pre> <p>Or using the <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/filter"><code>filter()</code></a> method in Arrays which was introduced in JavaScript 1.6:</p> <pre><code>var numbers = [1, 2, 3, 21, 22, 30]; var evens = numbers.filter(function(i) { return i % 2 === 0; }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload