<?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" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Bhuvan Malik on Medium]]></title>
        <description><![CDATA[Stories by Bhuvan Malik on Medium]]></description>
        <link>https://medium.com/@bhuvanmalik?source=rss-9c8c668181b8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*r9NE_FvEbAv7oKnBMLY_tg@2x.jpeg</url>
            <title>Stories by Bhuvan Malik on Medium</title>
            <link>https://medium.com/@bhuvanmalik?source=rss-9c8c668181b8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 07:01:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bhuvanmalik/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[An introduction to functional Reactive programming in Redux]]></title>
            <link>https://medium.com/free-code-camp/an-introduction-to-functional-reactive-programming-in-redux-b0c14d097836?source=rss-9c8c668181b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0c14d097836</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[tech]]></category>
            <dc:creator><![CDATA[Bhuvan Malik]]></dc:creator>
            <pubDate>Sat, 28 Apr 2018 18:40:59 GMT</pubDate>
            <atom:updated>2018-04-28T18:40:59.438Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8qnkQscHUXopU2ZBwNhHrg.jpeg" /></figure><p>Letss start off by getting the basic idea of what “Reactive Programming” is:</p><blockquote><strong><em>Reactive Programming</em></strong><em> is an asynchronous </em><a href="https://en.wikipedia.org/wiki/Programming_paradigm"><em>programming paradigm</em></a><em> concerned with </em><a href="https://en.wikipedia.org/wiki/Dataflow_programming"><em>data streams</em></a><em> and the propagation of change.<br>- Wikipedia</em></blockquote><p><a href="http://reactivex.io/">ReactiveX</a> or Rx is the most popular API for reactive programming. It’s built on the ideologies of the Observable Pattern, Iterator Pattern, and Functional Programming. Rx has libraries for different languages, but we will be using <a href="https://github.com/ReactiveX/rxjs">RxJS</a>.</p><h4>Rx is based on <strong>Observables</strong>, <strong>Observers,</strong> and <strong>Operators</strong></h4><p>An Observer essentially <strong>subscribes</strong> to an Observable.</p><p>The Observable then emits streams of data which the Observer listens and reacts to, setting in motion a chain of operations on the data stream. The real power comes from Operators or “Reactive Extensions” (hence the term Rx)<strong>.</strong></p><p>Operators allow you to transform, combine, manipulate, and work with the sequences of items emitted by Observables.</p><p>If you’re not familiar with Rx, you may have a hard time understanding and using <a href="https://redux-observable.js.org/">Redux-Observable</a>. So I suggest that you get your hands dirty with Rx first!</p><p>Now onto using RxJS with Redux.</p><h3>Redux-Observable</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*zSFfCEJqlPNer89DeE3xzw.png" /></figure><h4>Redux-Observable is an RxJS based middleware for Redux</h4><p>This is what Redux Docs have to say about middleware in Redux:</p><blockquote><em>Middleware provides a third-party extension point between dispatching an action, and the moment it reaches the reducer.</em></blockquote><p>Redux middleware can be used for logging, crash reporting, talking to an asynchronous API, routing, and more. Or we can say <strong>side effects </strong>in general.</p><h4>So how does Redux-Observable do all that?</h4><p>Through <a href="https://redux-observable.js.org/docs/basics/Epics.html">Epics</a>. Epics are the core primitive of Redux-Observable. An epic is just a simple function that takes in an action and then returns another action. <strong>Action In → Action Out</strong>. Actions are therefore treated as streams.</p><p>Every action dispatched in any component of React will pass through such functions (Epics) as a stream.</p><p>Let’s see what a simple Epic that takes in an action &#39;PING’ and returns a <strong>new</strong> action &#39;PONG’ looks like:</p><pre>const pingEpic = action$ =&gt;<br>  action$.filter(action =&gt; action.type === &#39;PING&#39;)<br>    .mapTo({ type: &#39;PONG&#39; })</pre><p>The $ after action is used to indicate that these variables are referencing streams. So we have a stream of actions being passed into the Epic on which we have used the filter operator of RxJS.</p><p>This filter operator filters out all the actions which are not of the type PING! Therefore, the Epic pingEpic is only concerned with handling actions of the type ‘PING’. Finally, this action ‘PING’ is mapped to a new action of the type ‘PONG’ satisfying the main rule of Epics: <strong>Action In → Action Out</strong>.</p><p>Since every epic is only concerned with a specific type of action, we have a special operator for action$(stream) to filter out unwanted actions from the stream. This operator is the ofType() operator.</p><p>Rewriting the previous Epic using ofType we get:</p><pre>const pingEpic = action$ =&gt;<br>  action$.ofType(&#39;PING&#39;)<br>  .mapTo({ type: &#39;PONG&#39; })</pre><p>If you want your epic to allow more than one type of action, the ofType() operator can take any number of arguments like so: ofType(type1, type2, type3,...).</p><h4>Getting Into The Specifics of How Epics Work</h4><p>You may think that the action ‘PING’ simply comes in and gets consumed by this epic. That is not the case. There are two things to always remember:</p><ol><li>Every action always goes to the reducer first</li><li>Only after that is that action received by the epic</li></ol><p>Therefore, the Redux cycle works normally as it should.</p><p>The action ‘PING’ reaches the reducer first and is then received by the Epic, then changed to a new action ‘PONG’ which is dispatched to the reducer.</p><p>We can even access the store’s state inside an Epic because an Epic’s second argument is a light version of the Redux Store! See below:<br>const myEpic = (action$, store) =&gt; <br>We can just call store.getState() and access the state inside Epics.</p><h4>Operator Chaining</h4><p>Between receiving an action and dispatching a new one, we can do all sorts of async side effects we want to, such as AJAX calls, web sockets, timers, and so on. This is done using the numerous <strong>operators</strong> provided by Rx.</p><blockquote><em>These Rx operators allow you to compose asynchronous sequences together in a declarative manner with all the efficiency benefits of callbacks but without the drawbacks of nesting callback handlers that are typically associated with asynchronous systems.</em></blockquote><p>We get the benefits of callbacks, without that notorious ‘callback hell’.</p><p>See how we can leverage the power of operators below.</p><h4>A Common Use-Case</h4><p>Assume that we want to search for a word with something like a dictionary API using text entered by the user in real-time. We’re basically dealing with storing (in the Redux store) and displaying the results from the API call. We would also like to debounce the API call so that the API is called within, say, 1 second of when the user stops typing.</p><p>This is how it’ll be done using Epic and RxJS operators:</p><pre>const search = (action$, store) =&gt;<br>  action$.ofType(&#39;SEARCH&#39;)<br>  .debounceTime(1000)<br>  .mergeMap(action =&gt;<br>    ajax.getJSON(`<a href="https://someapi/words/$%7Baction.payload%7D%60">https://someapi/words/${action.payload}`</a>)<br>     .map(payload =&gt; ({ type: &#39;SET_RESULTS&#39;, payload }))<br>     .catch(payload =&gt; Observable.of({type: &#39;API_ERROR&#39;, payload}))<br>  )</pre><p>Too much to handle?! Don’t worry, let’s break that down.</p><p>The epic is getting a stream of actions all oftype ‘SEARCH’. Since the user is continuously typing, the payload of every incoming action (action.payload) contains the updated search string.</p><p>The operator debounceTime() is used to filter out some of the actions in the stream except the last one. It basically passes an action through it only if 1 second has elapsed without it receiving another action or observable.</p><p>We then make the AJAX request, mapping the results to another action &#39;set_RESULTS&#39; which takes the response data (payload) to the reducer, which is the Action Out part.</p><p>Any API errors are caught using the catch operator. A new action is emitted with the error details and later displays a toaster with the error message.</p><p>Notice how the catch is inside the mergeMap() and after the AJAX request? This is because the mergeMap() creates a chain that is isolated. Otherwise the error would reach ofType() and will terminate our Epic. If that happens, the Epic will stop listening to any action in the future!</p><p>We can use traditional promises for AJAX requests as well. However, they have this inherent problem of not being able to get cancelled. So another important use case for using Epics is AJAX cancellation.</p><p>We use the takeUntil operator to handle this issue. This is done just like we used that catch operator inside mergeMap and after the AJAX request.</p><p>This is because takeUntil must stop the current AJAX request and not the entire Epic! Therefore, isolating operator chains is important here as well.</p><p>Debouncing, throttling, filtering, AJAX cancellation and others, are just the tip of the iceberg. We have a myriad of <a href="http://reactivex.io/documentation/operators.html">operators</a> at our disposal, making difficult use-cases trivial to solve. Using these operators, you can get as creative as your imagination allows you to be! Functional Reactive Programming (FRP) is elegant in its own way.</p><p>My focus for this article was on the explanation part of FRP in Redux using Redux-Observable. For setting up Redux-Observable in React+Redux, refer to the <a href="https://redux-observable.js.org/">official docs</a> — its very well documented, detailed, and easy-breezy.</p><p>Be sure to check out my other article on Redux which explores the best practice for creating reducers:</p><p><a href="https://medium.freecodecamp.org/reducing-the-reducer-boilerplate-with-createreducer-86c46a47f3e2">Reducing the Reducer Boilerplate With createReducer()</a></p><p>Want to improve your JavaScript basics? Give these a read:</p><ul><li><a href="https://medium.freecodecamp.org/es6-functions-9f61c72b1e86">JavaScript ES6 Functions: The Good Parts</a></li><li><a href="https://medium.freecodecamp.org/what-is-variable-hoisting-differentiating-between-var-let-and-const-in-es6-f1a70bb43d">A guide to JavaScript variable hoisting 🚩 with let and const</a></li><li><a href="https://medium.freecodecamp.org/function-hoisting-hoisting-interview-questions-b6f91dbc2be8">Function Hoisting &amp; Hoisting Interview Questions</a></li></ul><p>Peace ✌️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0c14d097836" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/an-introduction-to-functional-reactive-programming-in-redux-b0c14d097836">An introduction to functional Reactive programming in Redux</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Function Hoisting & Hoisting Interview Questions]]></title>
            <link>https://medium.com/free-code-camp/function-hoisting-hoisting-interview-questions-b6f91dbc2be8?source=rss-9c8c668181b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6f91dbc2be8</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Bhuvan Malik]]></dc:creator>
            <pubDate>Wed, 06 Dec 2017 22:20:40 GMT</pubDate>
            <atom:updated>2017-12-07T20:21:15.214Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v7kHrep8UBwgPvFz0gWutw.jpeg" /></figure><p>This is a part 2 for my previous article on Hoisting titled “<a href="https://medium.freecodecamp.org/what-is-variable-hoisting-differentiating-between-var-let-and-const-in-es6-f1a70bb43d">A guide to JavaScript variable hoisting 🚩 with let and const</a>”. So make sure you read that before diving into this one.</p><p>Previously I talked about variable hoisting only because function hoisting in JavaScript is not the same as variable hoisting, it is unique in its own way. I’ll expand on function hoisting in this one along with some common and tricky interview questions on hoisting (variable and function) which anyone giving JavaScript interviews is almost certain to encounter.</p><p>Hopefully, after finishing these 2 parts, you will be ready to cross off Hoisting from your JavaScript prep checklist!</p><p>Let’s get to it.</p><h3>Function Hoisting</h3><p>There are 2 ways of creating functions in JavaScript, through <strong>Function Declaration</strong> and through <strong>Function Expression</strong>. Let’s see what these are and how hoisting affects them.</p><h4>Function Declaration</h4><p>The <strong>function declaration</strong> defines a function with the specified parameters.<br>Syntax:</p><pre>function name(param1, param2, ...) {<br>  [statements]<br>}</pre><p>In JavaScript, function declarations hoist the function definitions.</p><p>Therefore, these functions can be <strong>used</strong> before they are declared.<br>Example:</p><pre>hoisted() // output: &quot;Hoisted&quot;</pre><pre>function hoisted() {<br>  console.log(&#39;Hoisted&#39;)<br>}</pre><p>Behind the scenes, this is how the JavaScript interpreter looks at the above code:</p><pre>// Hoisted code<br>function hoisted() {<br>  console.log(&#39;Hoisted&#39;)<br>}</pre><pre>// Rest of the code<br>hoisted() // output: &quot;Hoisted&quot;</pre><p>This behavior is true if you have function declarations in the Global Scope or Functional Scope (basically Local Scope in JavaScript).</p><p>This can be helpful because you can use your higher-level logic at the beginning of the code making it more readable and understandable.</p><p><strong>Note:</strong> Never use function declarations inside if/else blocks.</p><h4>Function Expression</h4><p>The <strong>function</strong> keyword can also be used to define a function inside an expression.<br>Syntax:</p><pre>const myFunction = function [name](param1, param2, ...) {<br>  [statements]<br>}</pre><p>The [name] is optional, therefore these can be anonymous functions. We can use arrow functions as well like so:</p><pre>const myFunction = (param1, param2, ...) =&gt; {<br>  [statements]<br>}</pre><p>Function expressions in JavaScript are not hoisted.</p><p>Therefore, you cannot use function expressions before defining them.<br>Example:</p><pre>notHoisted() // TypeError: notHoisted is not a function</pre><pre>const notHoisted = function() {<br>  console.log(&#39;foo&#39;)<br>}</pre><p>This is all there is to be kept in mind for creating functions from a hoisting point of view. <br>Now on to some interview questions!</p><h3>Hoisting Interview Questions</h3><p>Hoisting and it’s erratic behavior is a hot topic during interviews. Using the knowledge from my <a href="https://medium.freecodecamp.org/what-is-variable-hoisting-differentiating-between-var-let-and-const-in-es6-f1a70bb43d">previous article</a> and this one, one can sail through any questions on the topic. With that said, let’s look at some common questions.</p><h4>Question 1</h4><pre>var a = 1;</pre><pre>function b() {<br>  a = 10;<br>  return;</pre><pre>  function a() {}<br>}</pre><pre>b();</pre><pre>console.log(a);</pre><p><strong>Output: 1, </strong>What the?! 😱</p><p>This is because the function a() {} statement has now created a local a that has a functional/local scope. This new a now gets hoisted to the top of its enclosing function b() with it’s declaration and definition. This is what is happening behind the scenes:</p><pre>var a = 1;</pre><pre>function b() {<br>  <strong>// Hoisted</strong><br>  function a() {}</pre><pre>  a = 10;<br>  return;<br>}</pre><pre>b();</pre><pre>console.log(a)</pre><p>Therefore, the statement a = 10; is no longer changing the value of the global a which remains to be 1, but rather it is changing the local a from a function to an integer value of 10. Since we are logging the global a, the output is 1.</p><p>Had the statement function a() {} not been there, the output would have been 10.</p><h4>Question 2</h4><pre>function foo(){<br>    function bar() {<br>        return 3;<br>    }<br>    return bar();<br>    function bar() {<br>        return 8;<br>    }<br>}<br>alert(foo());</pre><p><strong>Output: 8</strong></p><p>Both the bar() functions are function declarations and will therefore be hoisted to the top of foo() local scope. However, the bar() returning 8 will be hoisted after the one returning 3. Therefore, the one returning 8 will be executed.</p><p>Behind the scenes:</p><pre>function foo(){<br>    //Hoisted before<br>    function bar() {<br>        return 3;<br>    }<br>    // Hoisted after<br>    function bar() {<br>        return 8;<br>    }</pre><pre>    return bar();<br>    <br>}<br>alert(foo());</pre><h4>Question 3</h4><pre>function parent() {<br>    var hoisted = &quot;I&#39;m a variable&quot;;<br>    function hoisted() {<br>        return &quot;I&#39;m a function&quot;;<br>    }<br>    return hoisted(); <br>}<br>console.log(parent());</pre><p><strong>Output: “TypeError: hoisted is not a function”</strong></p><p>This one’s tricky. Its Function vs. Variable! Let’s break it down.</p><p>We know that when it comes to variable hoisting, only the declaration(with a value of “undefined”) is hoisted, not the definition!</p><p>In the case of function declarations, the definitions are hoisted as well!</p><p>Now, in such a case of multiple declarations(variable and function in the same scope) with the same identifier, the hoisting of variables is simply <strong>IGNORED</strong>. The the interpreter comes across the function declaration and hoists it. <br>Finally, the statement of variable assignment (which was not hoisted) is executed and “I’m a variable” is assigned to hoisted, which is a simple string value and not a function. Hence the error!</p><p>Here’s the behind the scenes for this problem:</p><pre>function parent() {</pre><pre>    // Function declaration hoisted with the definition<br>    function hoisted() {<br>        return &quot;I&#39;m a function&quot;;<br>    }</pre><pre>    // Declaration <strong>ignored</strong>, assignment of a string<br>    hoisted = &quot;I&#39;m a variable&quot;; </pre><pre>    return hoisted(); </pre><pre>}<br>console.log(parent());</pre><h4>Question 4</h4><pre>alert(foo());<br>function foo() {<br>  var bar = function() {<br>    return 3;<br>  };<br>  return bar();<br>  var bar = function() {<br>    return 8;<br>  };<br>}</pre><p><strong>Output: 3</strong></p><p>This one’s easy. The function foo() itself will be hoisted in the global scope as its a function declaration. As for inside foo(), its a clear case of function expression for both the bar()functions.</p><p>The second bar() will not be read by the interpreter ahead of time (no hoisting). The first one will be executed and returned.</p><h4>Question 5</h4><pre>var myVar = &#39;foo&#39;;</pre><pre>(function() {<br>  console.log(&#39;Original value was: &#39; + myVar);<br>  var myVar = &#39;bar&#39;;<br>  console.log(&#39;New value is: &#39; + myVar);<br>})();</pre><p><strong>Output: “Original value was: undefined”, “New value is: bar”</strong></p><p>In this one, again the global value of myVar (‘foo’) is out of the picture. This is because variable myVar is being declared and defined inside the local function scope and is therefore hoisted to the top of the <a href="https://developer.mozilla.org/en-US/docs/Glossary/IIFE">IIFE</a> with a value of ‘undefined’ which is logged first. The value ‘bar’ is then assigned and logged subsequently.</p><p>This concludes JavaScript Hoisting from my side. 🚩</p><p>Hope <a href="https://medium.freecodecamp.org/what-is-variable-hoisting-differentiating-between-var-let-and-const-in-es6-f1a70bb43d">both</a> the articles are of help to you.</p><p>Please check out the article below if you want to learn arrow functions and other ES6 functionality related to functions.</p><p><a href="https://medium.freecodecamp.org/es6-functions-9f61c72b1e86">JavaScript ES6 Functions: The Good Parts</a></p><p>Peace ✌️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6f91dbc2be8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/function-hoisting-hoisting-interview-questions-b6f91dbc2be8">Function Hoisting &amp; Hoisting Interview Questions</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introducing VocabDB]]></title>
            <link>https://medium.com/@bhuvanmalik/introducing-vocabdb-732eabaae1b6?source=rss-9c8c668181b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/732eabaae1b6</guid>
            <category><![CDATA[gmat]]></category>
            <category><![CDATA[english]]></category>
            <category><![CDATA[gre]]></category>
            <category><![CDATA[exam]]></category>
            <category><![CDATA[vocabulary]]></category>
            <dc:creator><![CDATA[Bhuvan Malik]]></dc:creator>
            <pubDate>Mon, 09 Oct 2017 02:55:06 GMT</pubDate>
            <atom:updated>2017-11-03T10:38:33.278Z</atom:updated>
            <content:encoded><![CDATA[<p>Decoding the ordeal of learning vocabulary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rn1VZlj86CFWaddx69741g.png" /></figure><p>Let me start off by introducing myself. I’m a software engineer, I completed Engineering in Computer Science in 2016 and I’ve worked for <a href="http://esri.in/">ESRI India</a> and <a href="http://dauble.com/">Dauble</a> since then. That being said, <strong>I’m preparing for the Graduate Record Examinations(GRE) as we speak</strong>.</p><p>It is a universally acknowledged truth that learning vocabulary forms the backbone of any aptitude test, be it the GRE, GMAT, SAT, CAT etc. It is hence, very important for one to navigate through the maze in the correct manner.<br>Long gone are the days of making lists on paper or taking printouts of curated lists. This age of technology allows us to redefine the methods of learning by making the process simpler and hands on which is exactly what our new product- <a href="http://vocabdb.org/"><strong>VocabDB</strong></a> allows one to do.</p><p>Wanting to improve my own vocabulary, I teamed up with my friend Rajat Sharma( <a href="https://medium.com/u/923b9579a727">Functional Reactive Ninja</a> ) to create <strong>this free product</strong>. <strong><em>VocabDB is essentially a product made by the students, for the students</em></strong>. It’s focus is thus, on features of utmost importance.</p><p>VocabDB adopts a flashcards based approach along with features such as storage &amp; organization of flashcards, searching, sorting, segregation into lists and many more.<br>Allow me to walk you through the salient features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*2nkrDcwq_rB77vGlEdk6jw.png" /></figure><h3>Flashcards</h3><p>Store words as flashcards complete with meaning, example sentence and pronunciation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KFS50eySBDa6xDpXrhhn9w.png" /></figure><h3>Storage &amp; Organization</h3><p>Search your words, sort them from A-Z, segregate them into lists or play a simple slideshow. You have all the powers!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vo8ZveeBrn5iC6QBV0SvBg.png" /><figcaption>Multiple select</figcaption></figure><h3>Games</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pUmuVhkruJ2lRYKEYD7NqQ.png" /></figure><p>Master the lists you created or the predefined ones provided by us by playing word games!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4bwcPIf-oTSlBkzzrOIaiQ.png" /></figure><h3>Explore</h3><p>The process of collecting words from different sources is tedious. VocabDB allows you to explore new words and make them your own, from right where you are.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MKdDThvcH9coY3yh4tOCog.png" /></figure><h3>Powered by Oxford Dictionaries</h3><p>Remember the pocket Oxford Dictionary that we were made to carry to our schools? <br>Well, that mini dictionary is all grown up now! VocabDB uses Oxford API for all the vocabulary data and the reliability that comes with it.</p><p>VocabDB is the complete solution for cracking that aptitude test or generally building your vocabulary.</p><p>We’ll be adding more features soon, such as personal notes against every word, starred words etc. if the response lives up to our expectations 🙂</p><p><strong>Please share </strong><a href="http://vocabdb.org/"><strong>vocabdb.org</strong></a><strong> with anyone who’ll benefit from it. It’s completely free!</strong></p><p>Feel free to comment if you have any queries, want to give feedback or want us to include a feature you’d love to use. <strong>We’re listening.</strong></p><p>E-Mail: vocabdbedu@gmail.com</p><p>Peace ✌️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=732eabaae1b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reducing the Reducer Boilerplate With createReducer()]]></title>
            <link>https://medium.com/free-code-camp/reducing-the-reducer-boilerplate-with-createreducer-86c46a47f3e2?source=rss-9c8c668181b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/86c46a47f3e2</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Bhuvan Malik]]></dc:creator>
            <pubDate>Mon, 14 Aug 2017 20:09:16 GMT</pubDate>
            <atom:updated>2019-04-09T04:46:30.069Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*qBvXcdtU2MeWhsdD9Cpu0g.png" /><figcaption>This article is a short and simple walk-through for reducing the reducer boilerplate by using a more functional approach.</figcaption></figure><p>First, a quick recap of what reducers in Redux are:</p><p><strong>Reducers are nothing but pure functions that take in the previous state and an action and return the new state.</strong></p><p>Two things to keep in mind are that they are <strong>pure</strong> and therefore <strong>don’t mutate the state</strong>.</p><p>With that out of the way, let’s get down to business.</p><p>When we start with redux, this is how we write a reducer:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15635e800f52327b7737e40dffeb6f19/href">https://medium.com/media/15635e800f52327b7737e40dffeb6f19/href</a></iframe><p>We have a search reducer which updates the state on the basis of different actions like setting the search results, updating the search string or changing state of a loader/spinner. Let’s assume it to be a <a href="http://redux.js.org/docs/recipes/reducers/SplittingReducerLogic.html">slice reducer</a>, which we can combine later using the combineReducers(reducers) function.</p><p>Now, if you’re like me, you may not fancy switch statements 😋</p><p>They come with too much boilerplate of their own. A reducer handling many action types using switch cases would be lengthy. And that wouldn’t look good now, would it?! The idea is to ditch the switch and move towards a more functional approach.</p><h3><strong>Let’s rethink this a little</strong></h3><p>What we can do is abstract all our switch case logic into “case functions” and create an object that maps action types to their corresponding case functions. We’ll call this object ‘actionHandlers’.<br>Below is the object:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e703e561a5ece58d9fedf1c388c1c62/href">https://medium.com/media/2e703e561a5ece58d9fedf1c388c1c62/href</a></iframe><p>As you can see, we now have a mapping from action types to case functions.</p><blockquote><em>Case functions are like small reducer functions that take state and incoming action as arguments and return a new slice of the state tree.</em></blockquote><p>Now we must create a “reducer creator” function to make use of our <strong>actionHandlers</strong> . This function will return another function which will actually be our reducer passed to combineReducers(). Behold:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9423304b40c49ba4513d0c80a4894ef/href">https://medium.com/media/d9423304b40c49ba4513d0c80a4894ef/href</a></iframe><p>As you can see, createReducer() is a closure returning another function. This returned function satisfies the form (previousState, action) =&gt; newState and is therefore going to be our actual slice reducer.</p><p>The returned reducer function can access both actionHandlers and initialState arguments of it’s enclosing function because of the closure. The initialState is used as the default argument for state . Inside the reducer function, we check if our actionHandlers has a property matching the incoming action type. If so, we execute that case function inside actionHandlers, passing in state and action. If the action type is not a property inside actionHandlers, we return the previous state.</p><p>You can find createReducer() in the <a href="http://redux.js.org/docs/recipes/ReducingBoilerplate.html">official Redux docs</a> as well.</p><p>This create reducer function can now be imported in different reducer files to create all our slice reducers!</p><p>The above function is verbose right now for explanation point of view. Let’s spice things up a bit! Below is the new and improved create reducer file. 😎</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/51a9ab352e9ff60e0a5f45ced26d6549/href">https://medium.com/media/51a9ab352e9ff60e0a5f45ced26d6549/href</a></iframe><p>I’ve shortened everything using lambdas and Ramda library’s ‘<a href="http://ramdajs.com/docs/#propOr">propOr</a>’ function. What the propOr function does is take the 2nd argument (a key) to check inside the 3rd argument (an object), and returns its value if found. Otherwise, it returns the default supplied from the 1st argument. The 1st argument, ‘<a href="http://ramdajs.com/docs/#identity">identity</a>’, is a function that just returns the parameter supplied to it.</p><p>So, a function is returned if found in actionHandlers which is executed using (state, action. In case the action is not found, propOr returns identity, which is executed with the same (state, action) arguments and returns the first argument supplied, which is state(the previous state in this case).</p><p>You can create your own ‘propOr’ and ‘identity’ functions, Ramda is just what I use.</p><p>Let me show the new search reducer file for you to get the overall picture of how we use our createReducer function with the actionHandlers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b217d265989e00aa90ad60c915091daa/href">https://medium.com/media/b217d265989e00aa90ad60c915091daa/href</a></iframe><p>The createReducer function is partially applied and returns our final slice reducer and is exported to a file where we use the combineReducers function.</p><p>Well, there you go, a good way for creating reducers and reducing the overall boilerplate. I hope this benefits you in some way :)</p><p>Here are some links to my previous articles:</p><ul><li><a href="https://medium.freecodecamp.com/es6-functions-9f61c72b1e86">JavaScript ES6 Functions: The Good Parts</a></li><li><a href="https://medium.freecodecamp.com/what-is-variable-hoisting-differentiating-between-var-let-and-const-in-es6-f1a70bb43d">A guide to JavaScript variable hoisting 🚩 with let and const</a></li></ul><p>Peace ✌️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86c46a47f3e2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/reducing-the-reducer-boilerplate-with-createreducer-86c46a47f3e2">Reducing the Reducer Boilerplate With createReducer()</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript ES6 Functions: The Good Parts]]></title>
            <link>https://medium.com/free-code-camp/es6-functions-9f61c72b1e86?source=rss-9c8c668181b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f61c72b1e86</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Bhuvan Malik]]></dc:creator>
            <pubDate>Mon, 20 Mar 2017 17:54:26 GMT</pubDate>
            <atom:updated>2017-05-07T21:04:21.507Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nND_xhKn-rWHi8nBShTH-Q.jpeg" /></figure><p>ES6 offers some cool new functional features that make programming in JavaScript much more flexible. Let’s talk about some of them — specifically, default parameters, rest parameters, and arrow functions.</p><p><strong>Fun tip</strong>: you can copy and paste any of these examples/code into <a href="https://babeljs.io/repl/">Babel REPL</a><strong><em> </em></strong>and you can see how ES6 code transpiles to ES5.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*Io0bwrj6Dxaj_TG6gqdVBA.gif" /></figure><h3><strong>Default Parameter Values</strong></h3><p>JavaScript functions have a unique feature that allows for you to pass any number of parameters during function call (actual parameters) regardless of the number of parameters present in the function definition (formal parameters). So you need to include default parameters just in case someone forgets to pass one of the parameter.</p><h4><strong>How default parameters would be implemented in ES5</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/892f1c2222afb0ee00b86e2cef152610/href">https://medium.com/media/892f1c2222afb0ee00b86e2cef152610/href</a></iframe><p>The above seems fine when we run it. number2 wasn’t passed and we checked this using the ‘||’ operator to return the second operand if the first is falsy. Thus, ‘10’ was assigned as a default value since number2 is undefined.</p><p>There’s just one problem though. What if someone passes ‘0’ as the second argument? ⚠</p><p>The above approach would fail because our default value ‘10’ would be assigned instead of the passed value, such as ‘0’. Why? Because ‘0’ is evaluated as falsy!</p><p>Let’s improve the above code, shall we?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be34ba286b8fef44df84f4d9b31f9c6c/href">https://medium.com/media/be34ba286b8fef44df84f4d9b31f9c6c/href</a></iframe><p>Agh! That’s too much code. Not cool at all. Let’s see how ES6 does it.</p><h4><strong>Default parameters in ES6</strong></h4><pre>function counts(<strong>number1 = 5</strong>, <strong>number2 = 10</strong>) {<br>  // do anything here<br>}</pre><p>number1 and number2 are assigned default values of ‘5’ and ‘10’ respectively.<br>Well yeah, this is pretty much it. Short and sweet. No extra code to check for a missing parameter. This makes the body of the function nice and short. 🙃</p><p>NOTE: When a value of undefined is passed for a parameter with default argument, as expected the value passed is <strong>invalid</strong> and the <strong>default parameter value is assigned</strong>. But if null is passed, it is considered <strong>valid</strong> and the <strong>default parameter is not used</strong> and null is assigned to that parameter.</p><p>A nice feature of default parameters is that the default parameter doesn’t necessarily have to be a primitive value, and we can also execute a function to retrieve the default parameter value. Here’s an example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23459da53af322313ce7a67a4204bd3e/href">https://medium.com/media/23459da53af322313ce7a67a4204bd3e/href</a></iframe><p>Previous parameters can also be default parameters for the parameters that come after them like so:</p><pre>function multiply(first, second = first) {<br>  // do something here<br>}</pre><p>But the inverse will throw an error. That is, if second parameter is assigned as the default value for the first parameter, it results in an error because the second parameter is not yet defined while being assigned to the first parameter.</p><pre>function add(first = second, second) {<br>  return first + second;<br>}<br>console.log(add(undefined, 1)); //throws an error</pre><h3>Rest Parameters</h3><blockquote>A <em>rest</em> parameter is simply a named parameter which is preceded by three dots(…). This named parameter becomes an array which contains rest of the parameters(i.e apart from the named parameters) passed during function call.</blockquote><p>Just keep in mind that there can only be one <em>rest</em> parameter, and it has to be the last parameter. We can’t have a named parameter after a rest parameter.<br>Here’s an example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/67f382f6f399cb7de3862168399a6734/href">https://medium.com/media/67f382f6f399cb7de3862168399a6734/href</a></iframe><p>As you can see we’ve used the rest parameter to get all the keys/properties to be extracted from the passed object, which is the first parameter.</p><p>The difference between a rest parameter and the ‘arguments object’ is that the latter contains all the actual parameters passed during the function call, while the ‘rest parameter’ contains only the parameters that are not named parameters and are passed during the function call.</p><h3>Arrow Functions ➡</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UevUlm8aVqev2axt8iQWJw.jpeg" /></figure><p>Arrow Functions, or “fat arrow functions,” introduce a new syntax for defining functions that is very concise. We can avoid typing keywords like function, return and even curly brackets { } and parentheses ().</p><h4>Syntax</h4><p>The syntax comes in different flavors, depending on our usage. All the variations have one thing in <strong>common</strong>, i.e they begin with the<strong> arguments</strong>, followed by <strong>the</strong> <strong>arrow</strong> (=&gt;), followed by the <strong>function body</strong>.</p><p>The arguments and the body can take different forms. Here’s the most basic example:</p><pre>let mirror = value =&gt; value;</pre><pre>// equivalent to:</pre><pre>let mirror = function(value) {<br>  return value;<br>};</pre><p>The above example takes a single argument “value” (before the arrow) and simply returns that argument(=&gt; value;). As you can see, t<strong>here’s just the return value, so no need for return keyword or curly braces</strong> to wrap up the function body.</p><p>Since there is only <strong>one argument</strong>, there’s <strong>no need for parentheses</strong> “( )” as well.</p><p>Here’s an example with more than one argument to help you understand this:</p><pre>let add = (no1, no2) =&gt; no1 + no2;</pre><pre>// equivalent to:</pre><pre>let add = function(no1, no2) {<br>  return no1 + no2;<br>};</pre><p>If there are no arguments at all, you must include empty parentheses like below:</p><pre>let getMessage = () =&gt; &#39;Hello World&#39;;</pre><pre>// equivalent to:</pre><pre>let getMessage = function() {<br>  return &#39;Hello World&#39;;<br>}</pre><p>For a function body with just a return statement, curly braces are <strong>optional</strong>.<br>For a function body having more than just a return statement, you need to wrap the body in curly braces just like traditional functions.</p><p>Here’s a simple calculate function with two operations — add and subtract. Its body must be wrapped in curly braces:</p><pre>let calculate = (no1, no2, operation) =&gt; {<br>    let result;<br>    switch (operation) {<br>        case &#39;add&#39;:<br>            result = no1 + no2;<br>            break;<br>        case &#39;subtract&#39;:<br>            result = no1 - no2;<br>            break;<br>    }<br>    return result;<br>};</pre><p>Now what if we want a function that simply returns an object? The compiler will get confused whether the curly braces are of the object (()=&gt;<strong>{</strong>id: number<strong>}</strong> ) or curly braces of the function body.</p><p>The solution is to wrap the object in parentheses. Here’s how:</p><pre>let getTempItem = number =&gt; <strong>(</strong>{ id: number}<strong>)</strong>;</pre><pre>// effectively equivalent to:</pre><pre>let getTempItem = function(number) {<br>    return {<br>        id: number<br>    };<br>};</pre><p>Let’s have a look at the final example. In this we’ll use filter function on a sample array of numbers to return all numbers greater than 5,000:</p><pre>// with arrow function<br>let result = sampleArray.filter(element =&gt; element &gt; 5000);</pre><pre>// without arrow function<br>let result = sampleArray.filter(function(element) {<br>  return element &gt; 5000;<br>});</pre><p>We can see how much less code is necessary compared to the traditional functions.</p><p>A few things about arrow functions to keep in mind though:</p><ul><li>They can’t be called with <em>new</em>, can’t be used as constructors (and therefore lack prototype as well)</li><li>Arrow functions have their own scope, but there’s no ‘<em>this’</em> of their own.</li><li>No <em>arguments</em> object is available. You <strong>can use</strong> rest parameters however.</li></ul><p>Since JavaScript treats functions as first-class, arrow functions make writing functional code like lambda expressions and currying much easier.</p><blockquote>“Arrow functions were like rocket fuel for the functional programming explosion in JavaScript.” — Eric Elliott</blockquote><p>Well, there you go! Perhaps it’s time for you to start using these features.</p><p>ES6 features like these are a breath of fresh air, and developers just love using them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*BMHcup4PUdCGWFQ0hjtcFw.gif" /></figure><p>Here’s the <a href="https://medium.com/@bhuvanmalik/what-is-variable-hoisting-differentiating-between-var-let-and-const-in-es6-f1a70bb43d">link</a> to my previous post on variable declarations and hoisting!<br>I hope this motivates you to take ES6 head on if you haven’t already!</p><p>Peace ✌️️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f61c72b1e86" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/es6-functions-9f61c72b1e86">JavaScript ES6 Functions: The Good Parts</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A guide to JavaScript variable hoisting  with let and const]]></title>
            <link>https://medium.com/free-code-camp/what-is-variable-hoisting-differentiating-between-var-let-and-const-in-es6-f1a70bb43d?source=rss-9c8c668181b8------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1a70bb43d</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[es6]]></category>
            <dc:creator><![CDATA[Bhuvan Malik]]></dc:creator>
            <pubDate>Sun, 19 Feb 2017 17:28:14 GMT</pubDate>
            <atom:updated>2018-01-16T09:24:11.760Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*0hfm3TfurQboq6KlJrG56g.jpeg" /></figure><p>New JavaScript developers often have a hard time understanding the unique behaviour of variable/function <em>hoisting</em>.</p><p>Since we’re going to be talking about var, let and const declarations later on, it’s important to understand <em>variable hoisting</em> rather than <em>function hoisting</em>. Let’s dive in!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/245/1*OCkBhCR8R8V605XTM1tCnw.gif" /></figure><h3><strong>What is variable hoisting?</strong></h3><p>The JavaScript engine treats all variable declarations using “<em>var</em>” as if they are declared at the top of a functional scope(if declared inside a function) or global scope(if declared outside of a function) regardless of where the actual declaration occurs. This essentially is “<em>hoisting</em>”.</p><p>So variables might actually be available before their declaration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*q7BPDmcgkh2Sblc5EW2M8A.gif" /></figure><p>Let’s see it in action..</p><pre>// OUTPUT : undefined<br>console.log(shape);</pre><pre>var shape = &quot;square&quot;;</pre><pre>// OUTPUT : &quot;square&quot;<br>console.log(shape);</pre><p>If you’re coming from C-based languages, you’d expect an error to be thrown when the first console.log<em> </em>is called since the variable shape<em> </em>hadn’t been defined at that point. But the JavaScript interpreter looks ahead and “hoists” all variable declarations to the top, and the initialization remains in the same spot.</p><p>Here’s what is happening behind the scenes:</p><pre>//declaration getting hoisted at the top<br>var shape;</pre><pre>// OUTPUT : undefined<br>console.log(shape);</pre><pre>shape = &quot;square&quot;;</pre><pre>// OUTPUT : &quot;square&quot;<br>console.log(shape);</pre><p>Here is another example this time in a functional scope to make things more clear:</p><pre>function getShape(condition) {<br>    // shape exists here with a value of undefined</pre><pre>    // OUTPUT : undefined<br>    console.log(shape);</pre><pre>    if (condition) {<br>        var shape = &quot;square&quot;;<br>        // some other code<br>        return shape;<br>    } else {<br>        // shape exists here with a value of undefined<br>        return false;<br>    }<br>}</pre><p>You can see in the above example how shape’s declaration is hoisted at the top of getShape() function. This is because if/else blocks don’t create a local scope as seen in other languages. A local scope is essentially function scope in JavaScript. Therefore, shape is accessible everywhere outside the if<em> </em>block and within the function with an ‘<em>undefined’</em> value.</p><p>This default behaviour of JavaScript has its fair share of advantages and disadvantages. Not fully understanding these can lead to subtle but dangerous bugs in our code.</p><h3><strong>Enter Block-Level Declarations!</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*wNxUqEaF9ZB10WkgOrGtZw.gif" /></figure><p>ES6 introduced block-level scoping options to provide developers with more control and flexibility over a variable’s lifecycle.</p><p>Block-level declarations are made in block/lexical scopes that are created inside a block “{ }”.</p><h4>let Declarations</h4><p>This syntax is similar to var, just replace var with let to declare a variable with its scope being only that code block.</p><p>Place your let declarations at the top in a block so they’ll be available within that entire block.</p><p>For example:</p><pre>function getShape(condition) {<br>// <strong>shape doesn&#39;t exist here</strong></pre><pre>// console.log(shape); =&gt; <strong>ReferenceError: shape is not defined</strong></pre><pre>if (condition) {<br>        let shape = &quot;square&quot;;<br>        // some other code<br>        return shape;<br>    } else {<br>        // <strong>shape doesn&#39;t exist here as well</strong><br>        return false;<br>    }<br>}</pre><p>Notice how shape exists only inside the if block, and throws an error when accessed outside of it instead of outputting undefined like our previous case with var declarations.</p><p><strong>NOTE</strong> : If an identifier has already been defined inside a scope with var, using that same identifier in a let declaration inside the same scope throws an error.<br>Also, no error is thrown if a let declaration creates a variable with the same name as that of a variable in it’s outer scope. (This case is same with const declarations which we’ll talk about shortly.)</p><p>For example:</p><pre>var shape = &quot;square&quot;;<br><br>let shape = &quot;rectangle&quot;;</pre><pre>// SyntaxError: Identifier &#39;shape&#39; has already been declared</pre><p>and:</p><pre>var shape = &quot;square&quot;;<br>if (condition) {<br>    // doesn&#39;t throw an error<br>    let shape = &quot;rectangle&quot;;<br>    // more code <br>}<br>// No error</pre><h3>const Declarations</h3><p>The declaration syntax is similar to let &amp; var , lifecycle is the same as let. But you have to follow some rules.</p><p>Bindings declared using const are treated as <strong>constants</strong>, and<em> </em>therefore <strong>they cannot be re-assigned values once defined</strong>. Due to this, every const declaration <strong>must be initialized</strong> at the time of declaration.</p><p>For example:</p><pre>// valid <br>const shape = &quot;triangle&quot;;</pre><pre>// syntax error: missing initialization<br>const color;</pre><pre>// TypeError: Assignment to constant variable<br>shape = &quot;square&quot;</pre><p><strong>However</strong>, an object’s properties can be modified!</p><pre>const shape = {<br>    name: &quot;triangle&quot;,<br>    sides: 3<br>}</pre><pre>// WORKS<br>shape.name = &quot;square&quot;;<br>shape.sides = 4;</pre><pre>// SyntaxError: Invalid shorthand property initializer<br>shape = {<br>    name: &quot;hexagon&quot;,<br>    sides: 6<br>}</pre><p>In the above example we can see that only the properties of the shape object could be changed because we are only changing what shape contains, not what it’s bound to.</p><p>We can summarize by saying that const prevents modification of the binding as a whole — not the value that it’s bound to.</p><p>Note: Properties can be mutated. So for true immutability, use Immutable.js or Mori.</p><h3>The Temporal Dead Zone</h3><p>We now know that accessing let or const variables before they’re declared will throw a ReferenceError. This period between entering scope and being declared where they cannot be accessed is called the Temporal Dead Zone.</p><p>Note that “Temporal Dead Zone” isn’t formally mentioned in the ECMAScript specification. It’s just a popular term amongst programmers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/245/1*HLUGknnpXXGSFNsQ_dzmsg.gif" /></figure><p>I personally recommend you always use const, as it leads to fewer bugs. I have yet to encounter a situation where I needed to use var.</p><p>As a general rule, use let only for loop counters or only if you really need reassignment. Everywhere else, use const. Personally I’ve ditched loops for filter(), map() &amp; reduce(). You should too.</p><p><strong>Be sure to check out the part 2 for this on Function Hoisting and important interview questions related to the topic of hoisting in JS.</strong></p><p><a href="https://medium.freecodecamp.org/function-hoisting-hoisting-interview-questions-b6f91dbc2be8">Function Hoisting &amp; Hoisting Interview Questions</a></p><p>Click <a href="https://medium.com/@bhuvanmalik/es6-functions-9f61c72b1e86">here</a> for my article on some of the useful new features in ES6 related to functions.</p><p>See you next time. Peace! ✌️️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1a70bb43d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/what-is-variable-hoisting-differentiating-between-var-let-and-const-in-es6-f1a70bb43d">A guide to JavaScript variable hoisting 🚩 with let and const</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>