<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Exponential Operator - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Exponential Operator - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Mon, 25 May 2026 05:07:04 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/exponential-operator/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ The newest version of JavaScript only has 2 new features. Here’s how they work. ]]>
                </title>
                <description>
                    <![CDATA[ By Tiago Lopes Ferreira Let’s talk about the latest version of JavaScript: ECMAScript 2016 (more commonly known as ES7). ES7 brings two new features: Array.prototype.includes() and the new exponential operator: **. Array.prototype.includes() Gone are... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/why-could-es7-be-called-es2-4c5f094ccef7/</link>
                <guid isPermaLink="false">66c3668a139b845d61e84bd4</guid>
                
                    <category>
                        <![CDATA[ Exponential Operator ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Array Prototype Includes ]]>
                    </category>
                
                    <category>
                        <![CDATA[ es7 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 13 Oct 2017 06:42:34 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*4KuLQRBf9qZkEGUsFKZnJg.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Tiago Lopes Ferreira</p>
<p>Let’s talk about the latest version of JavaScript: ECMAScript 2016 (more commonly known as ES7). ES7 brings two new features: <code>Array.prototype.includes()</code> and the new exponential operator: <code>**</code>.</p>
<h3 id="heading-arrayprototypeincludes">Array.prototype.includes()</h3>
<p>Gone are the days where we used <code>.indexOf()</code> to know if an element <strong>existed</strong> in an array.</p>
<p>The key word is <strong><em>“exist.”</em></strong></p>
<p><code>.indexOf()</code> is fine if we want to know at which index a given element appears.</p>
<p>But if our goal is to know if a given element <strong>exists</strong> in an array, then <code>.indexOf()</code> is not the best option. And the reason is simple: When querying the existence of something we expect a boolean value, <strong>not a number</strong>.</p>
<p><code>Array.prototype.includes()</code> does exactly that. It determines if a given element exists in an array, returning <code>true</code> if it does, <code>false</code> otherwise.</p>
<h3 id="heading-into-the-specification">Into The Specification</h3>
<pre><code><span class="hljs-built_in">Array</span>.prototype.includes ( searchElement [ , fromIndex ] )
</code></pre><ul>
<li><code>searchElement</code> — the element to search for.</li>
<li><code>fromIndex</code> <em>(optional)</em> — the index from which to start to search.</li>
</ul>
<p>Diving into the <a target="_blank" href="https://www.ecma-international.org/ecma-262/7.0/">specification</a> feels like searching for power.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*4KuLQRBf9qZkEGUsFKZnJg.png" alt="Image" width="470" height="352" loading="lazy"></p>
<p>The specification says:</p>
<p>Let’s go step-by-step and try to understand the specification with examples.</p>
<ol>
<li>The difference here is the position of the element 4. Because our first example places 4 in the last position, includes will search the whole array. By specification <code>.includes()</code> returns immediately after finding the <code>searchElement</code>. This makes our second operation much faster.</li>
<li>The big difference with the <a target="_blank" href="https://www.ecma-international.org/ecma-262/7.0/#sec-samevaluezero">SameValueZero</a> algorithm versus the <a target="_blank" href="https://www.ecma-international.org/ecma-262/7.0/#sec-strict-equality-comparison">Strict Equality Comparison</a> (used by <code>.indexOf()</code>) is that it allows detecting the <strong>NaN</strong> elements.</li>
<li>It returns the boolean <code>true</code> when the element is found and <code>false</code> otherwise. No more indexes as result ?</li>
<li>As opposite to <code>.indexOf()</code>, <code>.includes()</code> does not skip missing array elements. Instead, it treats them as <strong>undefined</strong> values.</li>
</ol>
<p>Are you starting to feel the power?</p>
<p>We haven’t even touched <code>fromIndex</code>.</p>
<p>Let’s check the specification:</p>
<blockquote>
<p>The optional second argument <code>fromIndex</code> defaults to <code>0</code> (i.e. the whole array is searched). If it is greater than or equal to the length of the array, <strong>false</strong> is returned, i.e. the array will not be searched. If it is negative, it is used as the <strong>offset</strong> from the end of the array to compute <code>fromIndex</code>. If the computed index is less than <code>0</code>, the whole array will be searched.</p>
</blockquote>
<ol>
<li>If no <code>fromIndex</code> is provided them the default value of <code>0</code> is taken and the <strong>whole</strong> array is searched.</li>
<li><code>.includes()</code> immediately returns <strong>false</strong> when the value of <code>fromIndex</code> is bigger than array’s length.</li>
<li>When <code>fromIndex</code> is negative, then it’s value is calculated as <code>array.length — fromIndex</code>. This is particularly useful when searching on the last elements. For example, <code>fromIndex = -5</code> is the same as searching on the last 5 elements.</li>
<li>To avoid <code>.includes()</code> from breaking when the <code>fromIndex</code> calculated value is lower than 0, the whole array is searched. I would rather break ?</li>
</ol>
<p>OK — one last new feature…</p>
<h3 id="heading-the-exponential-operator"><code>The Exponential Operator (**)</code></h3>
<p>We’ve been waiting for the day we can play with exponential numbers like we play with addition, subtraction, multiplication, division.</p>
<p>Well, that day is here.</p>
<p>The operator <code>**</code> behaves exactly the same way as <code>Math.pow()</code>. It returns the result of raising the first operand to the power of the second (e.g. <code>x ** y</code>).</p>
<p>That’s it!</p>
<p>You now have the power of <strong>ES7</strong>! Use it well!</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*owhYyEq_wSRyPN_OuyQXPQ.gif" alt="Image" width="480" height="360" loading="lazy"></p>
<h3 id="heading-thanks-to">Thanks to ?</h3>
<ul>
<li><a target="_blank" href="http://2ality.com/2016/01/ecmascript-2016.html">2ality.com</a> by <a target="_blank" href="https://twitter.com/rauschma">Axel Rauschmayer</a></li>
<li><a target="_blank" href="https://www.ecma-international.org/ecma-262/7.0/">ECMAScript® 2016 Language Specification</a></li>
<li>To all <a target="_blank" href="https://www.youtube.com/watch?v=7yeA7a0uS3A">He-Man</a> fans</li>
<li><a target="_blank" href="https://medium.freecodecamp.org/">freeCodeCamp</a> for publishing ❤️</li>
</ul>
<p>Be sure to check out my articles on ES6:</p>
<p><a target="_blank" href="https://medium.freecodecamp.org/lets-explore-es6-generators-5e58ed23b0f1"><strong>Let’s explore ES6 Generators</strong></a><br><a target="_blank" href="https://medium.freecodecamp.org/lets-explore-es6-generators-5e58ed23b0f1">_Generators, aka, an implementation of iterables._medium.freecodecamp.org</a><a target="_blank" href="https://medium.freecodecamp.org/oh-yes-async-await-f54e5a079fc1"><strong>Oh Yes! Async / Await</strong></a><br><a target="_blank" href="https://medium.freecodecamp.org/oh-yes-async-await-f54e5a079fc1">_async / await is the new JavaScript syntax to declare an asynchronous function._medium.freecodecamp.org</a></p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
