<?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 Manu Bhardwaj on Medium]]></title>
        <description><![CDATA[Stories by Manu Bhardwaj on Medium]]></description>
        <link>https://medium.com/@immanubhardwaj?source=rss-b8b1f59e8abe------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*PvmgQdoOKq202FVQGk8J6A.jpeg</url>
            <title>Stories by Manu Bhardwaj on Medium</title>
            <link>https://medium.com/@immanubhardwaj?source=rss-b8b1f59e8abe------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 03:53:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@immanubhardwaj/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[React Interview Questions — Part 1 (React 18 & 19)]]></title>
            <link>https://codeburst.io/react-interview-questions-part-1-react-18-19-ba1b2e7b9e4a?source=rss-b8b1f59e8abe------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba1b2e7b9e4a</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Manu Bhardwaj]]></dc:creator>
            <pubDate>Mon, 25 Aug 2025 07:33:32 GMT</pubDate>
            <atom:updated>2025-08-25T07:33:32.566Z</atom:updated>
            <content:encoded><![CDATA[<h3>React Interview Questions — Part 1 (React 18 &amp; 19)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Xx1cck3B4iikKgmUbfStw.png" /></figure><p>React continues to dominate the front-end ecosystem, and interviewers love to test not just your fundamentals but also whether you’re keeping up with the latest releases. With <strong>React 18</strong> and <strong>React 19</strong> rolling out major features, candidates are now expected to understand concepts like <strong>automatic batching, concurrent rendering, server components, and the new Actions API</strong>.</p><p>This is the <strong>first article</strong> in my series on React Interview Questions, where I’ll cover intermediate-level questions that reflect real-world usage of React 18 and 19.</p><h3>1. What is Automatic Batching in React 18?</h3><p>Before React 18, React only batched state updates inside event handlers. Updates inside promises, setTimeout, or other asynchronous code would re-render the component multiple times.</p><p>With <strong>automatic batching</strong> in React 18, React now batches all state updates by default — even inside async functions. This reduces unnecessary re-renders and improves performance.</p><pre>// Before React 18 (multiple renders)<br>setTimeout(() =&gt; {<br>  setCount(c =&gt; c + 1); // re-render<br>  setFlag(f =&gt; !f);     // re-render again<br>}, 1000);<br><br>// React 18+ (automatic batching = single render)<br>setTimeout(() =&gt; {<br>  setCount(c =&gt; c + 1);<br>  setFlag(f =&gt; !f);<br>}, 1000);</pre><h3>2. Explain Concurrent Rendering and Why It Matters</h3><p>Concurrent rendering, introduced in React 18, allows React to prepare multiple versions of the UI simultaneously. This makes apps feel more <strong>responsive</strong> because React can pause, resume, or even abandon rendering work depending on user interactions.</p><p>For example, React can render a low-priority update (like fetching data) in the background while keeping high-priority updates (like typing into an input) responsive.</p><pre>const [isPending, startTransition] = useTransition();<br><br>function handleSearchChange(e) {<br>  startTransition(() =&gt; {<br>    setQuery(e.target.value); // low-priority update<br>  });<br>}</pre><h3>3. What are Server Components in React 19?</h3><p>Server Components allow parts of your React app to run <strong>on the server</strong> instead of the client. They are never sent to the browser as JavaScript. This reduces bundle size and improves performance.</p><p>Think of it as a way to render data-heavy UI pieces on the server, while keeping interactive components on the client.</p><pre>// Example: Server Component<br>export default async function ProductList() {<br>  const products = await db.products.findMany();<br>  return (<br>    &lt;ul&gt;<br>      {products.map(p =&gt; &lt;li key={p.id}&gt;{p.name}&lt;/li&gt;)}<br>    &lt;/ul&gt;<br>  );<br>}</pre><h3>4. What is the Actions API in React 19?</h3><p>React 19 introduces <strong>Actions API</strong> to simplify form handling and async state updates. It includes new hooks like:</p><ul><li><strong>useActionState</strong> — manage async form submissions</li><li><strong>useFormStatus</strong> — show loading/error states easily</li><li><strong>useOptimistic</strong> — instantly update UI while waiting for server confirmation</li></ul><pre>function Form() {<br>  const [state, formAction] = useActionState(<br>    async (prev, formData) =&gt; {<br>      await saveToDB(formData);<br>      return &quot;Saved!&quot;;<br>    },<br>    &quot;Idle&quot;<br>  );<br><br>  return (<br>    &lt;form action={formAction}&gt;<br>      &lt;input name=&quot;title&quot; /&gt;<br>      &lt;button type=&quot;submit&quot;&gt;Save&lt;/button&gt;<br>      &lt;p&gt;Status: {state}&lt;/p&gt;<br>    &lt;/form&gt;<br>  );<br>}</pre><h3>5. What is the React Compiler and Why is It Important?</h3><p>The <strong>React Compiler</strong> (introduced in React 19) automatically optimizes components to avoid unnecessary re-renders. Previously, developers had to use React.memo, useCallback, and useMemo carefully to prevent wasted renders. With the compiler, many of these optimizations are done automatically.</p><pre>// Before React 19<br>const MyComponent = React.memo(({ data }) =&gt; {<br>  return &lt;div&gt;{data}&lt;/div&gt;;<br>});<br><br>// React 19+ (compiler optimizes automatically)<br>function MyComponent({ data }) {<br>  return &lt;div&gt;{data}&lt;/div&gt;;<br>}</pre><blockquote>👉 <strong>Follow-up Question:</strong> Does the React Compiler mean we never need memo or useMemo anymore?</blockquote><h3>Final Thoughts</h3><p>This wraps up <strong>Part 1</strong> of my React Interview Questions series. We covered:</p><p>✅ Automatic batching (React 18)</p><p>✅ Concurrent rendering</p><p>✅ Server components (React 19)</p><p>✅ Actions API (React 19)</p><p>✅ React Compiler (React 19)</p><p>If you’re preparing for a React interview in 2025, knowing these concepts will give you an edge. In <strong>Part 2</strong>, I’ll cover more <strong>React 19 features</strong> like useFormStatus, optimistic UI patterns, and deeper dives into server actions.</p><blockquote>💡 <em>Tip for Interviews:</em> Don’t just memorize definitions — try coding small examples and explain the <strong>why</strong> behind each feature. That’s what interviewers look for.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba1b2e7b9e4a" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/react-interview-questions-part-1-react-18-19-ba1b2e7b9e4a">React Interview Questions — Part 1 (React 18 &amp; 19)</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Interview Questions: Promises]]></title>
            <link>https://codeburst.io/javascript-interview-questions-promises-1ab2fb7f0467?source=rss-b8b1f59e8abe------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ab2fb7f0467</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Manu Bhardwaj]]></dc:creator>
            <pubDate>Fri, 23 Oct 2020 23:10:46 GMT</pubDate>
            <atom:updated>2020-10-23T23:10:46.434Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*utN6q3uKPz6TpmjffgW_-w.png" /></figure><p>JavaScript has been the most used programming language for many years now, yet people continue to find it difficult to get a grasp of the language. This article will discuss some of the most frequently asked questions in JavaScript with the intention of helping readers overcome any confusion they may have around this language.</p><h4>Question</h4><p>What are the states of a promise?</p><h4>Solution</h4><ol><li>Pending</li><li>Fulfilled</li><li>Rejected</li></ol><h4>Question</h4><p>Can we use <strong>await</strong> only with promises?</p><h4>Solution</h4><p>No, we can use <strong>await</strong> with promise as well as any object that implements a <strong>then</strong> function.</p><pre>const thenable = {<br>  then: function(callback) {<br>    setTimeout(() =&gt; callback(2), 100);<br>  }<br>};<br><br>const value = await thenable;<br>console.log(value); // 2</pre><h4>Question</h4><p>What is the output of the following code?</p><pre>const promise = new Promise((resolve, reject) =&gt; {<br>  reject(Error(&#39;Some error occurred&#39;));<br>})<br>promise.catch(error =&gt; console.log(error.message));<br>promise.catch(error =&gt; console.log(error.message));</pre><h4>Solution</h4><pre>Some error occurred<br>Some error occurred</pre><p>You can add multiple handlers (<strong>catch</strong>, <strong>then,</strong> and <strong>finally</strong>) with a single promise.</p><h4>Question</h4><p>How can I write a sleep function using a promise?</p><h4>Solution</h4><pre>function sleep(ms) {<br>    return new Promise(res =&gt; {<br>        setTimeout(res, ms);<br>    });<br>}</pre><h4><strong>Question</strong></h4><p>What is the output of the following code?</p><pre>const promise = new Promise((resolve, reject) =&gt; {<br>    reject(Error(&#39;Some Error Occurred&#39;));<br>  })<br>  .catch(error =&gt; console.log(error))<br>  .then(error =&gt; console.log(error));</pre><h4><strong>Solution</strong></h4><pre>Some error occurred<br>undefined</pre><p>The<strong> catch</strong> function implicitly returns a promise, which can obviously be chained with a <strong>then. Since</strong> nothing is returned from the <strong>catch</strong> block, when error is logged in the <strong>then</strong> block it displays <strong>undefined</strong>.</p><h4>Question</h4><p>What is the output of the following code?</p><pre>const promise = new Promise(res =&gt; res(2));<br>promise.then(v =&gt; {<br>        console.log(v);<br>        return v * 2;<br>    })<br>    .then(v =&gt; {<br>        console.log(v);<br>        return v * 2;<br>    })<br>    .finally(v =&gt; {<br>        console.log(v);<br>        return v * 2;<br>    })<br>    .then(v =&gt; {<br>        console.log(v);<br>    });</pre><h4>Solution</h4><pre>2<br>4<br>undefined<br>8</pre><p>The<strong> finally</strong> block doesn’t receive any value, and anything returned from <strong>finally</strong> is not considered in the <strong>then</strong> block so the output from the last <strong>then</strong> is used.</p><h3>Wrapping Up</h3><p>In my personal opinion, while JavaScript isn’t the most complicated language it is a language with a lot of depth. If we can construct a clear understanding of the topics that we regularly use then it becomes extremely easy for us to get a better understanding of the nuances of JavaScript.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ab2fb7f0467" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/javascript-interview-questions-promises-1ab2fb7f0467">JavaScript Interview Questions: Promises</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Interview Questions: Arrays]]></title>
            <link>https://codeburst.io/javascript-interview-questions-arrays-f7a418d670f5?source=rss-b8b1f59e8abe------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7a418d670f5</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Manu Bhardwaj]]></dc:creator>
            <pubDate>Fri, 02 Oct 2020 03:10:39 GMT</pubDate>
            <atom:updated>2020-10-19T17:29:58.630Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*utN6q3uKPz6TpmjffgW_-w.png" /></figure><p>JavaScript has been the most used programming language for many years now, yet people continue to find it hard to get a grasp of. This article will discuss some of the most frequently asked questions in JavaScript.</p><h4>Question</h4><p>What is the output of the following code?</p><pre>const arrayOfOddNumbers = [1, 3, 5];<br>arrayOfOddNumbers[100] = 199;<br>console.log(arrayOfOddNumbers.length);</pre><h4>Solution</h4><pre>101</pre><p>The reason for this solution is as follows: JavaScript placesempty as a value for indices 3 - 99. Thus, when you set the value of the 100th index, the array looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*VdRoFprFAeOl-mjfpGTPXg.png" /></figure><p>And you get the length as 101.</p><h4>Question</h4><p>How can you double elements of an array using reduce? Please note that you cannot create additional variables.</p><h4>Solution</h4><pre>const arrayOfNumbers = [1, 2, 3, 4];</pre><pre>arrayOfNumbers.reduce((accumulator, currentValue, index, array) =&gt; array[index] = array[index] * 2);</pre><h4>Question</h4><p>What is the output of the following code snippet?</p><pre>let arrayOfLetters = [&#39;a&#39;,&#39;b&#39;,&#39;c&#39;,&#39;d&#39;,&#39;e&#39;,&#39;f&#39;];<br>const anotherArrayOfLetters = arrayOfLetters;<br>arrayOfLetters = [];<br>console.log(anotherArrayOfLetters);</pre><h4>Solution</h4><pre>[&#39;a&#39;,&#39;b&#39;,&#39;c&#39;,&#39;d&#39;,&#39;e&#39;,&#39;f&#39;]</pre><p>When we carry out the above (containing arrayOfLetters = []) you create a new array and break the old reference. Thus, anotherArrayOfLetters has no effect on it since it is still pointing to the old array.</p><h4>Question</h4><p>How could you print unique values from an array?</p><pre>const arrOfNum = [1, 2, 2, 4, 5, 6, 6];<br>console.log(getUniqueValues(arrOfNum)); <em>// [1, 2, 4, 5, 6]</em></pre><h4>Solution</h4><pre>function <em>getUniqueValues</em>(arrOfNum) {<br>  const set = new Set(arrOfNum);<br>  return [...set];<br>}</pre><p>A value in the Set <strong>may only occur once</strong>; it is unique in the Set&#39;s collection.</p><h4>Question</h4><p>How could you destructure array elements?</p><h4>Solution</h4><p>Without destructuring:</p><pre>const address = [&quot;583, Margaret Street&quot;, &quot;LOS ANGELES, CA&quot;, &quot;USA&quot;];</pre><pre>console.log(<br>  &quot;Address 1: &quot; + address[0],<br>  &quot;Address 2: &quot; + address[1],<br>  &quot;Address 3: &quot; + address[2]<br>);</pre><p>With destructuring:</p><pre>const [address1, address2, address3] = [&quot;583, Margaret Street&quot;, &quot;LOS ANGELES, CA&quot;, &quot;USA&quot;];</pre><pre>console.log(<br>  &quot;Address 1: &quot; + address1,<br>  &quot;Address 2: &quot; + address2,<br>  &quot;Address 3: &quot; + address3<br>);</pre><h3>Wrapping up</h3><p>In my personal opinion, JavaScript isn’t the most complicated language, however it is a language with a lot of depth. If we can construct a clear understanding of the topics that we regularly use then it becomes extremely easy for us to get a better understanding of the nuances of JaveScript.</p><p>Did you enjoy this article? If so, get more similar content by <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>subscribing to Decoded, our YouTube channel</strong></a><strong>!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7a418d670f5" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/javascript-interview-questions-arrays-f7a418d670f5">JavaScript Interview Questions: Arrays</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Interview Questions: Functions]]></title>
            <link>https://codeburst.io/javascript-interview-questions-functions-5a3081c1f3f5?source=rss-b8b1f59e8abe------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a3081c1f3f5</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[Manu Bhardwaj]]></dc:creator>
            <pubDate>Fri, 02 Oct 2020 03:10:17 GMT</pubDate>
            <atom:updated>2020-10-15T19:02:50.619Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*_xgzqzfcyhD06QS8.png" /></figure><p>JavaScript has been the most used programming language for many years now, yet people continue to struggle to grasp it. This article sets out to discuss some of the most frequently asked questions in JavaScript.</p><h3>Question</h3><p>What is the value of <strong>x </strong>&amp; <strong>y</strong>?</p><pre>const fn = (a, ...numbers, x, y) =&gt; {<br>    <em>console</em>.log(x, y)<br>};</pre><h3>Solution</h3><pre>SyntaxError: Rest parameter must be last formal parameter</pre><p>Rest parameters must always be the last argument to a function.</p><h3>Question</h3><p>Guess the output of the following code:</p><pre>var hero = {<br>    _name: &#39;John Doe&#39;,<br>    getSecretIdentity: function (){<br>        return this._name;<br>    }<br>};</pre><pre>var stoleSecretIdentity = hero.getSecretIdentity;</pre><pre><em>console</em>.log(stoleSecretIdentity());<br><em>console</em>.log(hero.getSecretIdentity());</pre><h3>Solution</h3><pre>undefined<strong><br></strong>John Doe</pre><p>The first console.log prints undefined because we are extracting the method from the hero object, so stoleSecretIdentity() is being invoked in the global context (i.e., the window object) where the _name property does not exist.</p><h3>Question</h3><p>What is the output of the following code snippet?</p><pre>function greet() {<br>    <em>console</em>.log(this.name);<br>}</pre><pre>const sayHello1 = greet.bind({name: &quot;Tom Cruise&quot;});<br>sayHello1();</pre><pre>const sayHello2 = sayHello1.bind({name: &quot;Zac Efron&quot;});<br>sayHello2();</pre><h3>Solution</h3><pre>Tom Cruise<br>Tom Cruise</pre><p>Binding an already bound function does not change the execution context.</p><h3>Question</h3><p>What will be logged to the console after running the snippet below?</p><pre>function greet() {<br>  setTimeout(function() {<br>    console.log(this.name);<br>  }, 500);<br>}</pre><pre>greet.call({name: &#39;Daniel Craig&#39;});</pre><h3>Solution</h3><pre>undefined</pre><p>In the snippet above, console.log is called inside an anonymous callback function passed to setTimeout. In this case, the callback function will create a context that is not explicitly set. In non-strict mode, this will be set to the global object. Even if we are calling the greet function with call and we are setting the context of hello to {name: &#39;Daniel Craig&#39;}, the callback function will not use the same context as the hello function and it will look for the name property on the global object. If a name property is defined it will return the value, otherwise it will log undefined.</p><h3>Question</h3><p>What will be logged to the console?</p><pre>function Employee(name) {<br>    this.name = name;<br>}</pre><pre>Employee.prototype.getName = () =&gt; {<br>    return this.name;<br>};</pre><pre>const jason = new Employee(&#39;Jason&#39;);<br><em>console</em>.log(jason.getName());</pre><h3>Solution</h3><pre>undefined</pre><p>The reason is that the snippet above is using an arrow function for getName. Arrow functions cannot create a context and therefore this will be the global object in non-strict mode.</p><h3>Question</h3><p>What is wrong with the code written below?</p><pre>var something = null;<br>var randomFunction = function () {<br>  var somethingElse = something;<br>  var unused = function () {<br>    if (somethingElse)<br>      console.log(&quot;hi&quot;);<br>  };<br>  something = {<br>    longStr: new Array(1000000).join(&#39;*&#39;),<br>    someMethod: function () {<br>      console.log(someMessage);<br>    }<br>  };<br>};<br>setInterval(randomFunction, 1000);</pre><h3>Solution</h3><p>somethingElse is only referenced in the main body of randomFunction, and in unused. unused itself (which we never even run) gets cleaned up once randomFunction ends. The only thing from randomFunction that escapes is the second closure, someMethod. And someMethod doesn&#39;t refer to somethingElse at all!</p><p>So even though there’s no way for any code to ever refer to somethingElse again, it never gets garbage collected. Why? Well, the typical way that closures are implemented is that every function object has a link to a dictionary-style object representing its lexical scope. If both functions defined inside randomFunction actually used somethingElse, it would be important that they both get the same object, even if somethingElse gets assigned to over and over, so both functions share the same lexical environment.</p><p>Now, Chrome&#39;s V8 JavaScript engine is apparently smart enough to keep variables out of the lexical environment if they aren&#39;t used by any closures: that&#39;s why the first example doesn&#39;t leak. But as soon as a variable is used by <em>any</em> closure, it ends up in the lexical environment shared by all closures in that scope. And that can lead to memory leaks.</p><h3>Wrapping up</h3><p>While in my personal experience I have not found JavaScript to be a complicated language, it does have a lot of nuances. If we can construct a clear understanding of the topics that we regularly use then it becomes extremely easy for us to get a hold of them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a3081c1f3f5" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/javascript-interview-questions-functions-5a3081c1f3f5">JavaScript Interview Questions: Functions</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Interview Questions: Objects]]></title>
            <link>https://codeburst.io/javascript-interview-questions-objects-171c1d86512d?source=rss-b8b1f59e8abe------2</link>
            <guid isPermaLink="false">https://medium.com/p/171c1d86512d</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Manu Bhardwaj]]></dc:creator>
            <pubDate>Fri, 19 Jun 2020 04:24:30 GMT</pubDate>
            <atom:updated>2020-06-24T09:40:59.715Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*utN6q3uKPz6TpmjffgW_-w.png" /></figure><p>JavaScript has been the most used programming language for so many years now, yet people find it hard to get a grasp on. Let’s discuss some of the most frequently asked questions in JavaScript:</p><h4>Question</h4><p>What is the output of the following code?</p><pre>var dwayne = {}, daniel = { firstName: &#39;Daniel&#39;}, jason = {key: &#39;jason&#39;};<br><br>dwayne[daniel]=123;<br>dwayne[jason]=456;<br><br>console.log(dwayne[daniel]);</pre><h4>Solution</h4><pre>456</pre><p>The reason for this is as follows: When setting an object property, JavaScript will implicitly stringify the parameter value. In this case, since daniel and jason are both objects, they will <em>both</em> be converted to &quot;[object Object]&quot;. As a result, dwayne[dani] anddwayne[jason] are both equivalent to dwayne[&quot;[object Object]&quot;] and can be used interchangeably. Therefore, setting or referencing dwayne[jason] is precisely the same as setting or referencing dwayne[daniel].</p><h4>Question</h4><p>What will be the output of the following code?</p><pre>const func = (function(a){<br>  delete a;<br>  return a;<br>})(5);<br><br>console.log(func);</pre><h4>Solution</h4><pre>5</pre><p>The output would be 5. The delete operator is used to delete properties from an object. Here a is not an object but a local variable. delete operators don&#39;t affect local variables.</p><h4>Question</h4><p>What is the output of the following code snippet?</p><pre>console.log({a:1} == {a:1});<br>console.log({a:1} === {a:1});</pre><h4>Solution</h4><pre>false<br>false</pre><p>In JavaScript, <strong>Objects</strong> are compared based on references.</p><p>In the above statement, we are comparing two different objects so their references will be different. Hence, we get the output as false for both of the statements.</p><h4>Question</h4><p>Which approach is better and why?</p><pre>const jamesBond = {<br>    firstName: &quot;Daniel&quot;,<br>    lastName: &quot;Craig&quot;,<br>    getFullName: function () {<br>        return `${this.firstName} ${this.lastName}`.trim();<br>    }<br>};</pre><pre>jamesBond.getFullName();</pre><p>or</p><pre>class Person {<br>    constructor(firstName, lastName) {<br>        this.firstName = firstName;<br>        this.lastName = lastName;<br>    }<br>}</pre><pre>Person.prototype.getFullName = function () {<br>    return `${this.firstName} ${this.lastName}`.trim();<br>};</pre><pre>const jamesBond = new Person(&quot;Daniel&quot;, &quot;Craig&quot;);</pre><pre>jamesBond.getFullName();</pre><h4>Solution</h4><p>Second approach is better since in the first approach, a closure is maintained for each copy of the object containing getFullName method. While in the second approach, the method is registered in the prototype rather than in every object. Thus, it is a more memory efficient approach.</p><h4>Question</h4><p>What is the difference between Object and Map?</p><h4>Solution</h4><ol><li><strong>Objects </strong>can have only strings and symbols as their keys while Map can have primitive, functions or even objects as their keys.</li><li>Keys in Map are ordered but not in objects.</li><li>Size of Map can be easily determined using size property while it’s relatively hard for objects.</li><li>A Map may perform better in scenarios involving frequent addition and removal of key pairs.</li></ol><h3>Wrapping up</h3><p>JavaScript is not a very vast language IMPO but it has a lot of depth in all that it holds in itself. If we can construct a clear understanding of the topics that we regularly use, it becomes extremely easy for us to get a hold on them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=171c1d86512d" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/javascript-interview-questions-objects-171c1d86512d">JavaScript Interview Questions: Objects</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vue Router: Route Resolvers]]></title>
            <link>https://medium.com/js-dojo/vue-router-route-resolvers-e7d09c991b58?source=rss-b8b1f59e8abe------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7d09c991b58</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vue-router]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[Manu Bhardwaj]]></dc:creator>
            <pubDate>Thu, 19 Sep 2019 08:13:34 GMT</pubDate>
            <atom:updated>2019-09-19T08:13:34.349Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9nJVHBfpLDm8g_zy.png" /><figcaption>Vue Router</figcaption></figure><h4>What is a Router Resolver?</h4><p>In the most simplest of terms, I’d say a Router Resolver allows you to get data before navigating to the new route.</p><h4>What’s the use case?</h4><p>One way to deal with getting and displaying data from an API is to route a user to a component, and then in that component’s <strong>created</strong> hook call a method in a service to get the necessary data. While getting the data, perhaps the component can show a loading indicator.</p><p>But, in cases where you want the API data to be fetched before the component is initialised, this strategy fails and this is where Route Resolvers are used.</p><h4><strong>How to implement?</strong></h4><p>Vue Router provides <strong>beforeEnter </strong>hook to take action before a route is resolved, we can use this hook as a point to bind our route resolver.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/0*EEWSXQyIZnNul5Xy.png" /><figcaption>Vue Router Hook</figcaption></figure><p>The resolver function is going to do the API calling stuff to resolve and set data in the destination route’s meta key.</p><p><strong>Route’s Meta</strong> is an object that contains additional information related to a route. We will utilise this object to store our data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7ACgR5aRUeUkuNN0.png" /><figcaption>Route Resolver</figcaption></figure><p>In the above code, <strong>getList</strong> is a function that returns Promise&lt;List&gt; and we await for the data to be resolved before we call <strong>next()</strong> to resume the routing.</p><p>Now, in the component we can consume the data by reading it from the route’s meta.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/0*RF9CmDx8LdbLStkC.png" /><figcaption>Data Consumption</figcaption></figure><p>So, this is how we can create and use Route Resolvers in Vue.Js.</p><p>Hope, you liked this article. Don’t forget to 👏 .</p><h3>Connect with me</h3><p>LinkedIn: <a href="https://www.linkedin.com/in/imanubhardwaj/">https://www.linkedin.com/in/imanubhardwaj/</a></p><p>Github: <a href="http://github.com/imanubhardwaj/">http://github.com/imanubhardwaj/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7d09c991b58" width="1" height="1" alt=""><hr><p><a href="https://medium.com/js-dojo/vue-router-route-resolvers-e7d09c991b58">Vue Router: Route Resolvers</a> was originally published in <a href="https://medium.com/js-dojo">Vue.js Developers</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Renderer2: Angular View Engine]]></title>
            <link>https://immanubhardwaj.medium.com/renderer2-angular-view-engine-d872498be1e6?source=rss-b8b1f59e8abe------2</link>
            <guid isPermaLink="false">https://medium.com/p/d872498be1e6</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[renderer2]]></category>
            <dc:creator><![CDATA[Manu Bhardwaj]]></dc:creator>
            <pubDate>Mon, 11 Feb 2019 16:09:48 GMT</pubDate>
            <atom:updated>2020-10-10T08:23:49.321Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*rflimdr9gUvwpfBG1D24Sw.jpeg" /></figure><p><strong>What is a View Engine ??</strong></p><p>View Engine is responsible for compiling the components so that they can be consumed by the browser. In Angular, we write our components using TypeScript and it cannot be run directly in browsers and for this purpose we require View Engines which would convert TS into JS.</p><p><strong>What is Renderer2 ??</strong></p><p>Renderer2 is Angular’s View Engine, it was introduced starting with Angular v4 to boost performance of Angular applications. It is responsibility of view engine to compile components to JS and HTML.</p><p><strong>Responsibilities of View Engine</strong></p><ol><li>Template Parsing</li><li>Tree-Shaking</li><li>Compilation</li></ol><h3><strong>Template Parsing</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*CcL5ojFBu9xkic10eMOzDA.png" /></figure><p>Every angular component has to go through a 4 step process to be rendered in the DOM by browser.</p><p>Firstly, all the decorators are stripped and their configurations are stored in <em>metadata.json </em>file<em>.</em></p><p>The template HTML is then converted into JavaScript instructions that are then used by the Angular Interpreter to understand how to display them in the DOM.</p><p><strong>Example:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dr0dXgU1WH2jaCK0qj3cBg.png" /></figure><p>Here the HTML is processed to generate instructions that contains all the details about the HTML.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UHBKWMoAEEQcEHHFKB2jBg.png" /></figure><p>All the nodes are observed to check presence of listeners, pipes, directives, etc. and then corresponding actions are attached to the rendered elements.</p><h3><strong>Tree Shaking</strong></h3><p>Tree Shaking is a process to remove dead code from the bundle. Renderer2 does a static analysis of the code, i.e., it doesn’t actually execute the code and then determine which part of code to be included in the bundle, but rather include all that has been mentioned in the code at least once.</p><p><strong>Example:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*ABoWRmNYLm6lV9CO4jCsBQ.png" /></figure><p>When above code is analysed by Renderer2, <em>getSomeData() </em>will be part of the final bundle, while logically it should not be because, <em>getSomeData() </em>will never be called due to falsy condition.</p><p>Let’s take another case into consideration:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d587cfcf0e91478f7e5de003df8ed7ef/href">https://medium.com/media/d587cfcf0e91478f7e5de003df8ed7ef/href</a></iframe><p>Flow until Angular v5</p><ul><li>Library Module imports Library Service <em>(for exposing interface and providing implementation)</em></li><li>Application Component imports Library Service <em>(for consuming interface)</em></li><li>Application Module imports Application Component</li><li>Application Module imports Library Module <em>(for configuring which implementation to inject)</em></li></ul><p>In above case, LibService will be included in the bundle even if no component uses it because it has been included in providers of LibModule.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dad14d80cb0d46296408bd2389502175/href">https://medium.com/media/dad14d80cb0d46296408bd2389502175/href</a></iframe><p>Flow starting from Angular v6</p><ul><li>Library Service imports Library Module</li><li>Application Component imports Library Service</li><li>Application Module imports Application Component</li><li>Application Module imports Library Module</li></ul><p>In new flow, LibService will not be included in bundle until it is being required by any Component because the scope of service is specified by the service itself not by the module.</p><h3>Compilation</h3><p>Renderer2 offers two variants of code compilation:</p><ol><li>Ahead Of Time Compilation (AOT)</li><li>Just In Time Compilation (JIT)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iwnUCeGl2zOa4x3r_KpzMg.png" /></figure><p>In JIT, the source code and Angular compiler are sent to browser and the whole template parsing process takes place in the browser environment.</p><p>In AOT, the template parsing process takes place at the developer end and thus causing a much smaller and faster build.</p><p>Some points of difference between AOT and JIT compilation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E1fSqgjfg0-whbPQzsuaiA.png" /></figure><p>You can also use “ng build — aot” or “ng serve — aot”. But, it doesn’t really make any sense to use AOT in ng serve or ng build. “ng build — prod” by default creates an AOT build.</p><p>That’s it, folks. Thanks for reading this far.</p><p>Follow me on Medium: <a href="https://medium.com/@immanubhardwaj">https://medium.com/@immanubhardwaj</a></p><p>Follow me on LinkedIn: <a href="https://www.linkedin.com/in/imanubhardwaj/">https://www.linkedin.com/in/imanubhardwaj</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d872498be1e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript: How to capture image from video?]]></title>
            <link>https://immanubhardwaj.medium.com/javascript-how-to-capture-image-from-video-ac7dba01a8e7?source=rss-b8b1f59e8abe------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac7dba01a8e7</guid>
            <category><![CDATA[canvas]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[html]]></category>
            <dc:creator><![CDATA[Manu Bhardwaj]]></dc:creator>
            <pubDate>Sat, 05 Jan 2019 15:25:49 GMT</pubDate>
            <atom:updated>2019-01-05T15:25:49.819Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Guedpz-wJ5fdffg75bNuIQ.png" /></figure><p>Ever wondered how to capture image from video using JavaScript? No? Follow my lead.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9fc4a36e5ab310ab1729cb0d01f8b8a/href">https://medium.com/media/c9fc4a36e5ab310ab1729cb0d01f8b8a/href</a></iframe><p>Basically, what we can do is draw the current instance of the video element on the canvas and then retrieve the blob from canvas and use that blob as source for image or upload the blob directly to storage like AWS or any other service.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1032733686abc6e45b23fe82a2bc651/href">https://medium.com/media/a1032733686abc6e45b23fe82a2bc651/href</a></iframe><p><strong>Line 6: </strong>We are drawing the video element on the canvas using drawImage function of canvas element.</p><blockquote><strong>Arguments:</strong> drawImage(element, startX, startY, widthOfImageToBeDrawn, heightOfImageToBeDrawn)</blockquote><p><strong>Line 7: </strong>Canvas element gives a callback to listen to the event after blob is prepared from canvas and is ready to be consumed.</p><p><strong>Line 9: </strong>window object comes with static function of URL class that can be used to get URL from blob.</p><p>In case, you want to merge a image with this generated image, you can:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/36ab0ff1ea326aafee43f8792c790785/href">https://medium.com/media/36ab0ff1ea326aafee43f8792c790785/href</a></iframe><p><strong>Line 12: </strong>Image element gives the callback when media is loaded.</p><p>Thanks for reading. 🙂</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac7dba01a8e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flutter: Interacting with internet using HttpClient and RxDart]]></title>
            <link>https://immanubhardwaj.medium.com/flutter-interacting-with-internet-using-httpclient-and-rxdart-21942462b632?source=rss-b8b1f59e8abe------2</link>
            <guid isPermaLink="false">https://medium.com/p/21942462b632</guid>
            <category><![CDATA[solid-principles]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Manu Bhardwaj]]></dc:creator>
            <pubDate>Sun, 23 Dec 2018 09:09:28 GMT</pubDate>
            <atom:updated>2018-12-23T10:42:26.731Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nCYCCJhDXYmXM_VE3iMeaQ.jpeg" /></figure><p><strong>Separation of concern(SOC)</strong> is an extensively used design principle. SOC principles states that <strong>a software system must be decomposed into parts that overlap in functionality as little as possible</strong>. It encourages us to write code in a way such that each section of our code address only one specific issue. There are various architectural patterns that follow this principle like in a traditional N-tier application structure, layers tend to include data access, business logic, and user interface layers.</p><p>We can start off by creating base methods for making Http requests:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56e44b2d608e9789fe8274fd7c81e389/href">https://medium.com/media/56e44b2d608e9789fe8274fd7c81e389/href</a></iframe><p>Creating base methods in this way help you reduce redundancy of code and easy to test functions.</p><p>Now, we can easily use these methods to construct our feature functions to be consumed by the UI layer:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0647bf7d3d92daf43f4089201e3b47ea/href">https://medium.com/media/0647bf7d3d92daf43f4089201e3b47ea/href</a></iframe><p>On top of that, we can make the class singleton so that same instance of this class is used by all the UI components residing in the application.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5b581f2111c8988599531fc0e0fb824/href">https://medium.com/media/f5b581f2111c8988599531fc0e0fb824/href</a></iframe><p>Making the class singleton is necessary because of one other reason that in cases when we want to store auth token of the user in a class variable and supply it in other Http requests. If we don’t make this class singleton then each UI component class will have unique instance of this HttpService class and thus value of authToken will be inconsistent among these instances.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c5ce01809a2d95eac2e0bcc102feefc/href">https://medium.com/media/4c5ce01809a2d95eac2e0bcc102feefc/href</a></iframe><p>After assembling above code, we get:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4fe47ce7e7124eff9f5b2bc94e70da3/href">https://medium.com/media/b4fe47ce7e7124eff9f5b2bc94e70da3/href</a></iframe><p>Now, the UI components can access data from this class in the following manner:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a02b17b98ad021825149f6269fed84ad/href">https://medium.com/media/a02b17b98ad021825149f6269fed84ad/href</a></iframe><p>Thanks for reading. 😀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=21942462b632" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>