<?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 Rahul Biswas on Medium]]></title>
        <description><![CDATA[Stories by Rahul Biswas on Medium]]></description>
        <link>https://medium.com/@rbiswas596?source=rss-8499b6585dc9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*lexLe2lmB5Fwqw7-zWq17g.jpeg</url>
            <title>Stories by Rahul Biswas on Medium</title>
            <link>https://medium.com/@rbiswas596?source=rss-8499b6585dc9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 02:19:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rbiswas596/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[PowerXGym— Mongo, Express React, Node (MERN)]]></title>
            <link>https://medium.com/@rbiswas596/powerxgym-mongo-express-react-node-mern-1530a9509d8c?source=rss-8499b6585dc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/1530a9509d8c</guid>
            <category><![CDATA[react-paypal]]></category>
            <category><![CDATA[react-web-development]]></category>
            <category><![CDATA[mern-stack]]></category>
            <category><![CDATA[react-project]]></category>
            <category><![CDATA[cloud-atlas]]></category>
            <dc:creator><![CDATA[Rahul Biswas]]></dc:creator>
            <pubDate>Wed, 03 Jun 2020 16:55:06 GMT</pubDate>
            <atom:updated>2020-06-03T16:55:06.491Z</atom:updated>
            <content:encoded><![CDATA[<h3>An overview of the technologies used for developing a MERN stack Gym Web App</h3><p>Following are the technologies that have been used for a gym website using the stack of Mongo, Express, React, and Node:</p><p>Project link: <a href="https://gym-power.netlify.app/">https://gym-power.netlify.app/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n6KTemh_G2wsmu7AV3LxMw.png" /></figure><h4>Formik</h4><p>Formik is a small library used to manage forms in web applications. It provides three essential features.</p><ol><li>Getting values in and out of form state</li><li>Validation and error messages</li><li>Handling form submission</li></ol><h4>react-PayPal-button-v2</h4><p>It is a React button component used for implementing PayPal’s Checkout. It also supports credit card checkout.</p><h4>Sass</h4><p>Sass is a CSS preprocessor, which adds special features such as variables, nested rules and mixins (sometimes referred to as syntactic sugar) into regular CSS. The aim is to make the coding process simpler and more efficient.</p><h4>Google Analytics</h4><p>Google Analytics is a web analytics service offered by Google. It is used for tracking customer/ visitor behavior in a website.</p><h4>Trello:</h4><p>Trello is, at its core, an online corkboard. You use it to organize “cards” into lists — those cards can be tasks, notes, projects, shared files, or anything else that helps your team work together.</p><h4>Node.js:</h4><p>Node.js is an open-source, cross-platform, JavaScript runtime environment that executes JavaScript code outside a web browser.</p><h4>Express.js:</h4><p>Express.js, or simply Express, is a web application framework for Node.js. It is designed for building web applications and APIs.</p><h4>Mongo DB:</h4><p>MongoDB is a cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas.</p><h4>Mongo Atlas:</h4><p>MongoDB Atlas is a fully-managed cloud database developed by the same people that build MongoDB. Atlas handles all the complexity of deploying, managing, and healing your deployments on the cloud service provider of your choice (AWS, Azure, and GCP).</p><h4>Heroku:</h4><p>Heroku is a cloud platform as a service (PaaS) supporting several programming languages. One of the first cloud platforms, Heroku has been in development since June 2007, when it supported only the Ruby programming language, but now supports Java, Node.js, Scala, Clojure, Python, PHP, and Go.</p><h4>Netlify:</h4><p>Netlify is a San Francisco-based cloud computing company that offers hosting and serverless backend services for web applications and static websites.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1530a9509d8c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mock Interview Q & A]]></title>
            <link>https://medium.com/@rbiswas596/mock-interview-q-a-4b3e8654e91c?source=rss-8499b6585dc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b3e8654e91c</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[js]]></category>
            <category><![CDATA[coding-interviews]]></category>
            <category><![CDATA[js-interview-questions]]></category>
            <dc:creator><![CDATA[Rahul Biswas]]></dc:creator>
            <pubDate>Sun, 17 May 2020 17:59:03 GMT</pubDate>
            <atom:updated>2020-05-17T17:59:03.796Z</atom:updated>
            <content:encoded><![CDATA[<h3>Summary of Milestone 3 (Day 7)</h3><p>Today we’ve practiced a mock interview, by using the previous preparation &amp; knowledge of JavaScript and our journey of the Milestone 3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*HdyCEetuHJQQKC-U7b9F-g.png" /></figure><h4>1. How does z-index works in CSS?</h4><p><strong>Answer: <br></strong>The z-index helps specify the stack order of positioned elements that may overlap one another. The z-index default value is zero and can take on either a positive or negative number.</p><p>An element with a higher z-index is always stacked above than a lower index.</p><p>Z-Index can take the following values:</p><ul><li><strong>Auto:</strong> Sets the stack order equal to its parents.</li><li><strong>Number:</strong> Orders the stack order.</li><li><strong>Initial:</strong> Sets this property to its default value (0).</li><li><strong>Inherit:</strong> Inherits this property from its parent element.</li></ul><h4>2. What is CSS flexbox? Write all the properties of the flexbox.</h4><p><strong>Answer:<br></strong>It allows us to design a flexible responsive layout structure without using any float or positioning property of CSS. To use CSS flexbox we need to define a flex container initially.</p><p><strong>Flexbox Properties:</strong></p><ul><li>flex-direction</li><li>flex-wrap</li><li>flex-flow</li><li>justify-content</li><li>align-items</li><li>align-content</li></ul><h4>3. What are the different ways to get an element from DOM?</h4><p><strong>Answer:<br></strong>We can retrieve DOM elements by using the followings:</p><blockquote>1.<strong> </strong>document.getElementById or just id</blockquote><blockquote>2. getElementsByTagName, getElementsByClassName</blockquote><blockquote>3. querySelectorAll</blockquote><h4>4. What are the differences between undefined and null?</h4><p><strong>Answer:</strong></p><p>undefined means a variable has been declared but has not yet been assigned a value. On the other hand, null is an assignment value.</p><p>undefined and null are two distinct types: undefined is a type itself (undefined) while null is an object.</p><h4>5. What’s Event Bubbling?</h4><p><strong>Answer:</strong></p><p>When an event happens on an element, the respective handler is run and is bubbled on to the parent element, the parent element handles the event and the event is bubbled on to its ancestors (except when the bubbling is stopped).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/0*wKdcZ76KgDBW2HCH.png" /></figure><h4>6. What is JSX?</h4><p><strong>Answer:</strong></p><p>JSX is a XML-like syntax extension to ECMAScript (the acronym stands for JavaScript XML). Basically it just provides syntactic sugar for the <strong><em>React.createElement()</em></strong> function, giving us expressiveness of JavaScript along with HTML like template syntax.</p><p>In the example below text inside &lt;h1&gt; tag return as JavaScript function to the render function.</p><pre>class App extends React.Component {<br>  render() {<br>    return(<br>      &lt;div&gt;<br>        &lt;h1&gt;{&#39;Welcome to React world!&#39;}&lt;/h1&gt;<br>      &lt;/div&gt;<br>    )<br>  }<br>}</pre><h4>7. What is Scope?</h4><p><strong>Answer:</strong></p><h4>8. What are Closure?</h4><p><strong>Answer:<br></strong>One of the powerful default behavior of JavaScript, which is interesting but confusing at the same time.</p><p>It’s known to us that in JS a child function can access all the function variables, objects, etc. from the parent class. But it is more interesting that even if the parent function is returned, the child function can still access the function variables, object, etc. from the parent class. Because the function properties are stored in memory. This feature is known as Closure in JavaScript.</p><p><strong>Example:</strong></p><blockquote>function closuresDemo() {<br>var x = 10;<br>return function() {<br>var y = 20;<br>console.log(‘Sum: ‘ + (x + y));<br>}<br>}</blockquote><h4>9. What is context?</h4><p><strong>Answer:<br></strong><em>Context</em> provides a way to pass data through the component tree without having to pass props down manually at every level. For example, authenticated user, locale preference, UI theme need to be accessed in the application by many components.</p><p><strong>Example:</strong></p><blockquote>const {Provider, Consumer} = React.createContext(defaultValue)</blockquote><h4>10. How to fetch data with React Hooks?</h4><p><strong>Answer:<br></strong>The <strong><em>useEffect </em></strong>hook is used to fetch the data from the API and to set the data in the local state of the component with the state hook’s update function.</p><p>Let&#39;s take an example in which it fetches list of react articles from the API</p><pre>import React, { useState, useEffect } from &#39;react&#39;;<br>import axios from &#39;axios&#39;;</pre><pre>function App() {<br>  const [data, setData] = useState({ hits: [] });</pre><pre>  useEffect(async () =&gt; {<br>    const result = await axios(<br>      &#39;http://hn.algolia.com/api/v1/search?query=react&#39;,<br>    );</pre><pre>    setData(result.data);<br>  }, []);</pre><pre>  return (<br>    &lt;ul&gt;<br>      {data.hits.map(item =&gt; (<br>        &lt;li key={item.objectID}&gt;<br>          &lt;a href={item.url}&gt;{item.title}&lt;/a&gt;<br>        &lt;/li&gt;<br>      ))}<br>    &lt;/ul&gt;<br>  );<br>}</pre><pre>export default App;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b3e8654e91c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fullstack Cafe JavaScript Challenges]]></title>
            <link>https://medium.com/@rbiswas596/fullstack-cafe-javascript-challenges-2e1da1139a97?source=rss-8499b6585dc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e1da1139a97</guid>
            <category><![CDATA[coding-interviews]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript-interview]]></category>
            <category><![CDATA[js]]></category>
            <dc:creator><![CDATA[Rahul Biswas]]></dc:creator>
            <pubDate>Sat, 16 May 2020 15:54:35 GMT</pubDate>
            <atom:updated>2020-05-16T16:02:38.115Z</atom:updated>
            <content:encoded><![CDATA[<h3>10 JavaScript Coding Problems from Fullstack Cafe - Milestone 3 (Day 6)</h3><p>Today we’ve practiced 25 JavaScript coding interview problems from <a href="https://www.fullstack.cafe/blog/javascript-code-interview-questions">fullstack.cafe</a>. Here we’ve presented 10 of them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*mB8f-cJy1N3ACbXdvgm8bA.png" /></figure><h4>1. Checking Anagrams of one another</h4><p><strong>Problems:<br></strong>Given two strings, return true if they are anagrams of one another.</p><p><strong>Solution:</strong></p><blockquote><strong>What is Anagram?</strong></blockquote><blockquote>An <strong>anagram </strong>is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. For example, the word anagram can be rearranged into nag a ram, or the word binary into brainy or the word adobe into abode.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wGSRYATqqYNx0egH_j3eag.png" /></figure><h4>2. Callback function</h4><p><strong>Problem:<br></strong>Explain what a callback function is and provide a simple example.</p><p><strong>Solution:<br></strong>A <strong><em>callback </em></strong>function is a function that is passed to another function as an argument and is executed after some operation has been completed. Below is an example of a simple callback function that logs to the console <em>after</em> some operations have been completed.</p><pre>function modifyArray(arr, callback) {<br>  // do something to arr here<br>  arr.push(100);<br>  // then execute the callback function that was passed<br>  callback();<br>}<br><br>var arr = [1, 2, 3, 4, 5];<br><br>modifyArray(arr, function() {<br>  console.log(&quot;array has been modified&quot;, arr);<br>});</pre><p><strong>The output will be:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*nTvy9eWBBkpyvvmLF5m8PA.png" /></figure><h4>3. FizzBuzz Challenge</h4><p><strong>Problem:<br></strong>Create a for loop that iterates up to <strong>100 </strong>while outputting <strong>&quot;fizz&quot;</strong> at multiples of <strong>3</strong>, <strong>&quot;buzz&quot;</strong> at multiples of <strong>5</strong> and <strong>&quot;fizzbuzz&quot;</strong> at multiples of <strong>3</strong> and <strong>5</strong>.</p><p><strong>Solution:</strong></p><pre>for (let i = 1; i &lt;= 100; i++) {<br>  let f = i % 3 == 0,<br>    b = i % 5 == 0;<br>  console.log(f ? (b ? &#39;FizzBuzz&#39; : &#39;Fizz&#39;) : b ? &#39;Buzz&#39; : i);<br>}</pre><p><strong>The output will be:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*MoO43AO_bgX4Y1xcespPGQ.png" /></figure><h4>4. “this” keyword</h4><p><strong>Problem:<br></strong>How does the “this” keyword work? Provide some code examples.</p><p><strong>Solution:<br></strong>In JavaScript, <strong><em>this</em> </strong>always refers to the “owner” of the function we’re executing, or rather, to the object that a function is a method of.</p><pre>function foo() {<br>    console.log( this.bar );<br>}<br><br>var bar = &quot;global&quot;;<br><br>var obj1 = {<br>    bar: &quot;obj1&quot;,<br>    foo: foo<br>};<br><br>var obj2 = {<br>    bar: &quot;obj2&quot;<br>};</pre><p><strong>The output will be:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*6G6cyV6AH7cxuwrMPWViqw.png" /></figure><h4>5. Recursive function</h4><p><strong>Problem:<br></strong>Write a recursive function that performs a Binary Search</p><p><strong>Solution:</strong></p><pre>function recursiveBinarySearch(array, value, leftPosition, rightPosition) {</pre><pre>  if (leftPosition &gt; rightPosition){<br>         return -1;<br>  } <br> <br>  var middlePivot = Math.floor((leftPosition + rightPosition) / 2);<br>  if (array[middlePivot] === value) {<br>    return middlePivot;<br>  } else if (array[middlePivot] &gt; value) {<br>    return recursiveBinarySearch(array, value, leftPosition, middlePivot - 1);<br>  } else {<br>    return recursiveBinarySearch(array, value, middlePivot + 1, rightPosition);<br>  }<br>}</pre><p><strong>The output will be:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/1*io5T8aMYUTOhb7exBkuFPw.png" /></figure><h4>6. Closure</h4><p><strong>Problem:<br></strong>What is “closure” in javascript? Provide an example?</p><p><strong>Solution:</strong></p><blockquote><strong>What is Closure?</strong></blockquote><blockquote>A <strong>closure </strong>is a function defined inside another function (called parent function) and has access to the variable which is declared and defined in parent function scope.</blockquote><blockquote>A closure can access:</blockquote><blockquote>i) Variable declared in his own scope</blockquote><blockquote>ii) Variable declared in parent function scope</blockquote><blockquote>iii) Variable declared in global namespace</blockquote><pre>var globalVar = &quot;abc&quot;;<br><br>// Parent self invoking function<br>(function outerFunction (outerArg) { // begin of scope outerFunction<br>  // Variable declared in outerFunction function scope<br>  var outerFuncVar = &#39;x&#39;;    <br>  // Closure self-invoking function<br>  (function innerFunction (innerArg) { // begin of scope innerFunction<br>    // variable declared in innerFunction function scope<br>    var innerFuncVar = &quot;y&quot;;<br>    console.log(         <br>      &quot;outerArg = &quot; + outerArg + &quot;\n&quot; +<br>      &quot;outerFuncVar = &quot; + outerFuncVar + &quot;\n&quot; +<br>      &quot;innerArg = &quot; + innerArg + &quot;\n&quot; +<br>      &quot;innerFuncVar = &quot; + innerFuncVar + &quot;\n&quot; +<br>      &quot;globalVar = &quot; + globalVar);<br>  // end of scope innerFunction<br>  })(5); // Pass 5 as parameter<br>// end of scope outerFunction<br>})(7); // Pass 7 as parameter</pre><p><strong>The output will be:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/447/1*GXviZrTxYD8UK6hOP_G4xQ.png" /></figure><h4>7. “delete” operator</h4><p><strong>Problem:<br></strong>What will be the output of the following code?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*_diaVB98rNEYhVrOLOUqhw.png" /></figure><p><strong>Solution:<br></strong>The output will be <strong><em>0</em></strong>. <strong><em>delete </em></strong>operator is used to delete a property from an object. Here <strong><em>x</em></strong> is not an object it&#39;s <strong>local variable</strong>. <strong><em>delete </em></strong>operator doesn&#39;t affect local variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*2oDBO4Q3n3Pk2HuMbYU2ow.png" /></figure><h4>8. “bind” function</h4><p><strong>Problem:<br></strong>When would you use the “bind” function?</p><p><strong>Solution:<br></strong>The <strong><em>bind()</em></strong> method creates a new function that, when called, has its <strong><em>this </em></strong>keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.</p><p>A good use of the <strong><em>bind </em></strong>function is when you have a particular function that you want to call with a specific this value. You can then use <strong><em>bind </em></strong>to pass a specific object to a function that uses a <strong><em>this </em></strong>reference.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*GerO3lQuu4a2QnBLugkQmQ.png" /></figure><h4>9. Private Variable</h4><p><strong>Problem:<br></strong>How would you create a private variable in JavaScript?</p><p><strong>Solution:<br></strong>To create a private variable in JavaScript that cannot be changed you need to create it as a local variable within a function. Even if the function is executed the variable cannot be accessed outside of the function. For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*fG1p8nfMWr5njG_xRXP3Jw.png" /></figure><p>To access the variable, a helper function would need to be created that returns the private variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*KvNbzC9hzE4ecCZDMgV0lQ.png" /></figure><h4>10. Enqueue and Dequeue</h4><p><strong>Problem:<br></strong>Implement enqueue and dequeue using only two stacks.</p><p><strong>Solution:<br></strong><em>Enqueue</em> means to add an element, <em>dequeue</em> to remove an element.</p><pre>var inputStack = []; // First stack<br>var outputStack = []; // Second stack<br><br>// For enqueue, just push the item into the first stack<br>function enqueue(stackInput, item) {<br>  return stackInput.push(item);<br>}<br><br>function dequeue(stackInput, stackOutput) {<br>  // Reverse the stack such that the first element of the output stack is the<br>  // last element of the input stack. After that, pop the top of the output to<br>  // get the first element that was ever pushed into the input stack<br>  if (stackOutput.length &lt;= 0) {<br>    while(stackInput.length &gt; 0) {<br>      var elementToOutput = stackInput.pop();<br>      stackOutput.push(elementToOutput);<br>    }<br>  }<br><br>  return stackOutput.pop();<br>}</pre><p><strong>The output will be:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*HFcgikaUNjnwSEVASJz8eA.png" /></figure><p><strong>That’s all for today…Thanks for reading. Give a clap if you liked this article. Happy Learning :)</strong></p><p><strong><em>Article Reference:</em></strong></p><p><a href="https://www.fullstack.cafe/blog/javascript-code-interview-questions"><em>https://www.fullstack.cafe/blog/javascript-code-interview-questions</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e1da1139a97" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HackerRank JavaScript Challenges]]></title>
            <link>https://medium.com/@rbiswas596/hackerrank-javascript-challenges-f2e822160df6?source=rss-8499b6585dc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/f2e822160df6</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[hackerrank-solution]]></category>
            <category><![CDATA[js]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Rahul Biswas]]></dc:creator>
            <pubDate>Fri, 15 May 2020 17:44:22 GMT</pubDate>
            <atom:updated>2020-05-15T17:44:22.032Z</atom:updated>
            <content:encoded><![CDATA[<h3>10 JavaScript Coding Problems from HackerRank - Milestone 3 (Day 5)</h3><p>Today we’ve solved several JavaScript coding interview problems from hackerrank.com. Here we’ve presented 10 of them.</p><h4>1. Functions</h4><p><strong>Problem: <br></strong>Implement a function named factorial that has one parameter: an integer, . It must return the value of (i.e., factorial).</p><p><strong>Solution:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xLu68yt-EfG6IvyAzA6--w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lZesL9xFIGVRpnvtTzgyRw.png" /></figure><h4>2. Let and Const</h4><p><strong>Problem: <br>1.</strong> Declare a constant variable, <strong>PI</strong>, and assign it the value <strong><em>Math.PI</em></strong>. You will not pass this challenge unless the variable is declared as a constant and named <strong>PI </strong>(uppercase).<br><strong>2.</strong> Read a number, <strong>r</strong>, denoting the radius of a circle from stdin.<br><strong>3.</strong> Use <strong>PI </strong>and <strong>r</strong> to calculate the <strong>area </strong>and <strong>perimeter </strong>of a circle having radius <strong>r</strong>.<br><strong>4.</strong> Print <strong>area</strong> as the first line of output and print <strong>perimeter</strong> as the second line of output.</p><p><strong>Solution:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*UxhaLnLTq7mdbmbc5laR9Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fm21lLmOxlBbVUtXM9o9kA.png" /></figure><h4>3. Conditional Statements: If-Else</h4><p><strong>Problem:<br></strong>Complete the <strong><em>getGrade(score)</em></strong> function in the editor. It has one parameter: an integer, <strong><em>score</em></strong>, denoting the number of points Julia earned on an exam. It must return the letter corresponding to her <strong><em>grade </em></strong>according to the following rules:</p><ul><li>If <strong><em>25 &lt; score ≤ 30</em></strong> , then <strong><em>grade = A</em></strong>.</li><li>If <strong><em>20 &lt; score ≤ 25</em></strong> , then <strong><em>grade = B</em></strong>.</li><li>If 1<strong><em>5 &lt; score ≤ 20</em></strong> , then <strong><em>grade = C</em></strong>.</li><li>If <strong><em>10 &lt; score ≤ 15</em></strong> , then <strong><em>grade = D</em></strong>.</li><li>If <strong><em>5 &lt; score ≤ 10</em></strong> , then <strong><em>grade = E</em></strong>.</li><li>If <strong><em>0 &lt; score ≤ 5</em></strong> , then <strong><em>grade = F</em></strong>.</li></ul><p><strong>Solution:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*3MgFSZmE4vqRRiLiqk8UmQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FSVE-KcvXb3IgVkYH6Vi6w.png" /></figure><h4>4. Conditional Statements: Switch</h4><p><strong>Problem:<br></strong>Complete the <strong><em>getLetter(s)</em></strong> function in the editor. It has one parameter: a string, <strong><em>s</em></strong>, consisting of lowercase English alphabetic letters (i.e., <strong><em>a</em></strong> through <em>z</em>). It must return <strong><em>A, B, C,</em></strong> or <strong><em>D</em></strong> depending on the following criteria:</p><ul><li>If the first character in string <strong><em>s</em></strong> is in the set <strong><em>{a, e, i, o, u}</em></strong>, then return <strong><em>A</em></strong>.</li><li>If the first character in string <strong><em>s</em></strong> is in the set <strong><em>{b, c, d, f, g}</em></strong>, then return <strong><em>B</em></strong>.</li><li>If the first character in string <strong><em>s</em></strong> is in the set <strong><em>{h, j, k, l, m}</em></strong>, then return <strong><em>C</em></strong>.</li><li>If the first character in string <strong><em>s</em></strong> is in the set <strong><em>{n, p, q, r, s, t, v, w, x, y, z}</em></strong>, then return <strong><em>D</em></strong>.</li></ul><p><strong>Hint:</strong> You can get the letter at some index in using the syntax <strong><em>s[i]</em></strong> or <strong><em>s.charAt(i)</em></strong>.</p><p><strong>Solution:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/1*GhGlvRqhfIfx8B-1_8Oy2Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NxTA9_bTKrTF92354reteg.png" /></figure><h4>5. Loops</h4><p><strong>Problem:<br></strong>Complete the <strong><em>vowelsAndConsonants </em></strong>function in the editor below. It has one parameter, a string, <strong><em>s</em></strong>, consisting of lowercase English alphabetic letters (i.e., a through z). The function must do the following:</p><ol><li>First, print each vowel in <strong><em>s</em></strong> on a new line. The English vowels are a, e, i, o, and u, and each vowel must be printed in the same order as it appeared in <strong><em>s</em></strong>.</li><li>Second, print each consonant (i.e., non-vowel) in <strong><em>s</em></strong> on a new line in the same order as it appeared in <strong><em>s</em></strong>.</li></ol><p><strong>Solution:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6aG6jtDNX82fuwGE9HRpSA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7tFhRFS7GYrq6m5Kmktc2A.png" /></figure><h4>6. Arrays</h4><p><strong>Problem:<br></strong>Complete the <strong><em>getSecondLargest </em></strong>function in the editor below. It has one parameter: an array, <strong><em>nums</em></strong>, of <strong><em>n</em></strong> numbers. The function must find and return the second largest number in <strong><em>nums</em></strong>.</p><p><strong>Solution:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*3ELJ1QoEpyZGvGU8tKOMig.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i0b7pYxuFM2qNk-lweW4Mw.png" /></figure><h4>7. Try, Catch, and Finally</h4><p><strong>Problem:<br></strong>Complete the <em>reverseString </em>function; it has one parameter,<strong><em> s</em></strong>. You must perform the following actions:</p><ol><li>Try to reverse string <strong><em>s</em></strong> using the split, reverse, and join methods.</li><li>If an exception is thrown, catch it and print the contents of the exception’s <strong><em>messages </em></strong>on a new line.</li><li>Print <strong><em>s </em></strong>on a new line. If no exception was thrown, then this should be the reversed string; if an exception was thrown, this should be the original string.</li></ol><p><strong>Solution:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kCmfNpmfMxt6rh--pU0slA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WtrkK9Eyc11rxk6zXvsJ1A.png" /></figure><h4>7. Throw</h4><p><strong>Problem:<br></strong>Complete the isPositive function below. It has one integer parameter, <strong><em>a</em></strong>. If the value of <strong><em>a </em></strong>is positive, it must return the string <strong><em>YES</em></strong>. Otherwise, it must throw an Error according to the following rules:</p><ul><li>If <strong><em>a </em></strong>is <em>0</em>, throw an Error with<em> </em><strong><em>message </em></strong><em>= Zero Error</em>.</li><li>If <strong><em>a</em></strong> is negative, throw an Error with <strong><em>message </em></strong><em>= Negative Error</em>.</li></ul><p><strong>Solution:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*68DfbGK8Ar19DRHZZUXCVg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T76b86vc0TibwPd3sZ_O2g.png" /></figure><h4>8. Create a Rectangle Object</h4><p><strong>Problem:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nXQfjGHYzFz71W_KHOcBdQ.png" /></figure><p><strong>Solution:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G19MIi9io4jo6rNdZ7G5uA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M2CuDHaQboe9ZWgWWcDhXQ.png" /></figure><h4>9. Count Objects</h4><p><strong>Problem:<br></strong>Complete the function in the editor. It has one parameter: an array, <strong><em>a</em></strong>, of objects. Each object in the array has two integer properties denoted by <strong><em>x</em></strong> and <strong><em>y</em></strong>. The function must return a count of all such objects <strong><em>o</em></strong> in array <strong><em>a</em></strong> that satisfy <strong><em>o.x == o.y</em></strong>.</p><p><strong>Solution:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*caRBox0tRDmY4x0BkXKIMg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f_qgTaiwK2uXe3XRJ55UAA.png" /></figure><h4>10. Classes</h4><p><strong>Problem:<br></strong>Create a Polygon class that has the following properties:</p><ul><li>A constructor that takes an array of integer values describing the lengths of the polygon’s sides.</li><li>A perimeter() method that returns the polygon’s perimeter.</li></ul><p>Locked code in the editor tests the Polygon constructor and the perimeter method.</p><p><strong>Note:</strong> The perimeter method must be lowercase and spelled correctly.</p><p><strong>Solution:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Qv-btBHNYGkxQi2_mRaNw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zk-ew6DCDYMLgHvGUekZuQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f2e822160df6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Interview Questions]]></title>
            <link>https://medium.com/analytics-vidhya/react-interview-questions-272936f3e1fe?source=rss-8499b6585dc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/272936f3e1fe</guid>
            <category><![CDATA[js]]></category>
            <category><![CDATA[react-interview]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Rahul Biswas]]></dc:creator>
            <pubDate>Thu, 14 May 2020 15:46:08 GMT</pubDate>
            <atom:updated>2020-05-15T15:57:19.159Z</atom:updated>
            <content:encoded><![CDATA[<h3>Milestone 3 - Day 4</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*_GHPqt27yGkiYGL4KevOnQ.png" /></figure><h4>1. How to perform automatic redirect after login?</h4><p>Rendering a <strong><em>&lt;Redirect&gt; </em></strong>component, which is provided by <strong><em>react-router </em></strong>package, will navigate to a new location. Like server-side redirects, the new location will override the current location in the history stack.</p><pre>import React, { Component } from &#39;react&#39;<br>import { Redirect } from &#39;react-router&#39;<br><br>export default class LoginComponent extends Component {<br>  render() {<br>    if (this.state.isLoggedIn === true) {<br>      return &lt;Redirect to=&quot;/your/redirect/page&quot; /&gt;<br>    } else {<br>      return &lt;div&gt;{&#39;Login Please&#39;}&lt;/div&gt;<br>    }<br>  }<br>}</pre><h4>2. How to format date using React Intl?</h4><p>The <strong><em>injectIntl()</em></strong> higher-order component will give you access to the <strong><em>formatDate()</em></strong> method via the props in your component. The method is used internally by instances of <strong><em>FormattedDate </em></strong>and it returns the string representation of the formatted date.</p><pre>import { injectIntl, intlShape } from &#39;react-intl&#39;<br><br>const stringDate = this.props.intl.formatDate(date, {<br>  year: &#39;numeric&#39;,<br>  month: &#39;numeric&#39;,<br>  day: &#39;numeric&#39;<br>})<br><br>const MyComponent = ({intl}) =&gt; (<br>  &lt;div&gt;{`The formatted date is ${stringDate}`}&lt;/div&gt;<br>)<br><br>MyComponent.propTypes = {<br>  intl: intlShape.isRequired<br>}<br><br>export default injectIntl(MyComponent)</pre><h4>3. Are there any similarities between Redux and RxJS?</h4><p>Though both are used for different purposes, there are few similarities between them:</p><blockquote><strong>i)</strong> <strong>Redux</strong> is a tool for managing state throughout the application. It is usually used as an architecture for UIs, which can be presumed 50% as an alternative to Angular.</blockquote><blockquote><strong>RxJS</strong> is a reactive programming library. It is usually used as a tool to accomplish asynchronous tasks in JavaScript. It can be presumed as an alternative to JavaScript Promises.</blockquote><blockquote><strong>ii)</strong> <strong>Redux</strong> uses the Reactive paradigm because the Store is reactive. The Store observes actions from a distance, and changes itself.</blockquote><blockquote><strong>RxJS</strong> also uses the Reactive paradigm, but instead of being an architecture, it gives us basic building blocks, Observables, to accomplish this pattern.</blockquote><h4>4. What is state in React?</h4><p>In the <strong>React</strong> sense, “<strong>state</strong>” is an object that represents the parts of the app that can change. Each component can maintain its own <strong>state</strong>, which lives in an object called this.<strong>state</strong>.</p><blockquote>State is private and fully controlled by the component. No other component can access the state except the one that owns it.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/0*q4iKgmOS74sRKW_Q.jpg" /></figure><p><strong>Example of a state:</strong></p><pre>class User extends React.Component {<br>  constructor(props) {<br>    super(props)<br><br>    this.state = {<br>      message: &#39;Welcome to React world&#39;<br>    }<br>  }<br><br>  render() {<br>    return (<br>      &lt;div&gt;<br>        &lt;h1&gt;{this.state.message}&lt;/h1&gt;<br>      &lt;/div&gt;<br>    )<br>  }<br>}</pre><h4>5. How to pass a parameter to an event handler or callback?</h4><p><strong>Method 1:<br></strong>Using <em>arrow function</em></p><blockquote>&lt;button onClick={() =&gt; this.handleClick(id)} /&gt;</blockquote><p>which is equivalent to call the <strong><em>bind()</em></strong> function</p><blockquote>&lt;button onClick={this.handleClick.bind(this, id)} /&gt;</blockquote><p><strong>Method 2:</strong></p><p>Passing arguments to an array function</p><blockquote>&lt;button onClick={this.handleClick(id)} /&gt;<br>handleClick = (id) =&gt; () =&gt; { console.log(“Hello, your ticket number is”, id) };</blockquote><h4>6. What is the purpose of using super constructor with props argument?</h4><p>A child class constructor cannot make use of <strong><em>this </em></strong>reference until <strong><em>super() </em></strong>method has been called. The same applies for ES6 sub-classes as well. The main reason for passing props parameter to <strong><em>super()</em></strong> call is to access <strong><em>this.props </em></strong>in the child constructors.</p><blockquote><strong>this.props</strong> is different only within the constructor. It would be the same outside the constructor.</blockquote><p><strong>Passing props:</strong></p><pre>class MyComponent extends React.Component {<br>  constructor(props) {<br>    super(props)</pre><pre>    console.log(this.props) // prints { name: &#39;John&#39;, age: 42 }<br>  }<br>}</pre><p><strong>Not passing props:</strong></p><pre>class MyComponent extends React.Component {<br>  constructor(props) {<br>    super()</pre><pre>    console.log(this.props) // prints undefined</pre><pre>    // but props parameter is still available<br>    console.log(props) // prints { name: &#39;John&#39;, age: 42 }<br>  }</pre><pre>  render() {<br>    // no difference outside constructor<br>    console.log(this.props) // prints { name: &#39;John&#39;, age: 42 }<br>  }<br>}</pre><h4>7. What is the impact of indexes as keys?</h4><p>React needs to keep track of the elements, for that reason <strong><em>Keys</em></strong> should be always stable, unique &amp; predictable.</p><p><strong>Example:</strong><br>The following code limits the React’s optimizations capability. Here each element’s key will be based on ordering, rather than tied to the data that is being represented.</p><pre>{todos.map((todo, index) =&gt;<br>  &lt;Todo<br>    {...todo}<br>    key={index}<br>  /&gt;<br>)}</pre><p>But, if we use element data for unique key, assuming <strong><em>todo.id</em></strong> is unique to this list and stable, React would be able to reorder elements without needing to reevaluate them as much.</p><pre>{todos.map((todo) =&gt;<br>  &lt;Todo {...todo}<br>    key={todo.id} /&gt;<br>)}</pre><h4>8. Do I need to rewrite all my class components with hooks?</h4><p>Not necessarily. But we can try Hooks in a few components (or new components) without rewriting any existing code. Because there are no plans to remove classes in ReactJS.</p><h4>9. Is Hooks cover all use cases for classes?</h4><p>Hooks doesn’t cover all use cases of classes but there is a plan to add them soon. Currently, there are no Hook equivalents to the uncommon <strong><em>getSnapshotBeforeUpdate </em></strong>and <strong><em>componentDidCatch </em></strong>lifecycles yet.</p><h4>10. How to ensure hooks followed the rules in your project?</h4><p>We can ensure this by using ESLint plugin called <strong><em>eslint-plugin-react-hooks</em></strong><em> </em>(released by React Team)</p><p><strong>Two rules are there:</strong></p><p><em>i) Add the plugin in the project (by executing the command line)</em></p><blockquote>npm install eslint-plugin-react-hooks@next</blockquote><p><em>ii) Applying the below config in </em><strong><em>ESLint config file</em></strong></p><pre>{<br>  &quot;plugins&quot;: [<br>    // ...<br>    &quot;react-hooks&quot;<br>  ],<br>  &quot;rules&quot;: {<br>    // ...<br>    &quot;react-hooks/rules-of-hooks&quot;: &quot;error&quot;<br>  }<br>}</pre><p><strong>That’s all for today…Thank for Reading. Give a clap if you liked this article. Happy Learning :)</strong></p><p><strong><em>Article Reference:</em></strong></p><p><a href="https://github.com/sudheerj/reactjs-interview-questions"><em>https://github.com/sudheerj/reactjs-interview-questions</em></a></p><p><a href="https://daveceddia.com/visual-guide-to-state-in-react/"><em>https://daveceddia.com/visual-guide-to-state-in-react/</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=272936f3e1fe" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/react-interview-questions-272936f3e1fe">React Interview Questions</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</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 (Part 2)]]></title>
            <link>https://medium.com/@rbiswas596/javascript-interview-questions-part-2-2c6990f9256c?source=rss-8499b6585dc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c6990f9256c</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[js]]></category>
            <category><![CDATA[javascript-interview]]></category>
            <category><![CDATA[coding-interviews]]></category>
            <dc:creator><![CDATA[Rahul Biswas]]></dc:creator>
            <pubDate>Wed, 13 May 2020 17:35:51 GMT</pubDate>
            <atom:updated>2020-05-13T17:36:33.220Z</atom:updated>
            <content:encoded><![CDATA[<h3>JavaScript Interview Questions (Part-2)</h3><h3>Some tricky JS Coding Interview Questions</h3><p><strong>Milestone 3 (Day 3)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1TlrqD9NXu4F8c5th6JN2Q.png" /></figure><h4>1. The following recursive code will cause a stack overflow if the array list is too large. How can you fix this and still retain the recursive pattern?</h4><pre>var list = readHugeList();</pre><pre>var nextListItem = function() {<br>    var item = list.pop();</pre><pre>    if (item) {<br>        // process the list item...<br>        nextListItem();<br>    }<br>};</pre><p><strong>Answer:<br></strong>The potential stack overflow can be avoided by modifying the <strong><em>nextListItem </em></strong>function as follows:</p><pre>var list = readHugeList();</pre><pre>var nextListItem = function() {<br>    var item = list.pop();</pre><pre>    if (item) {<br>        // process the list item...<br>        setTimeout( nextListItem, 0);<br>    }<br>};</pre><p>The stack overflow is eliminated because the event loop handles the recursion, not the call stack. When <strong><em>nextListItem </em></strong>runs, if <strong><em>item </em></strong>is not null, the timeout function (<strong><em>nextListItem</em></strong>) is pushed to the event queue and the function exits, thereby leaving the call stack clear. When the event queue runs its timed-out event, the next <strong><em>item </em></strong>is processed and a timer is set to again invoke <strong><em>nextListItem</em></strong>. Accordingly, the method is processed from start to finish without a direct recursive call, so the call stack remains clear, regardless of the number of iterations.</p><h4>2. Create a function that, given a DOM Element on the page, will visit the element itself and <em>all</em> of its descendants (<em>not just its immediate children</em>). For each element visited, the function should pass that element to a provided callback function.</h4><h4>The arguments to the function should be:</h4><h4>i) a DOM element</h4><h4>ii) a callback function (that takes a DOM element as its argument)</h4><p><strong>Answer:<br></strong>Visiting all elements in a tree (DOM) is a classic Depth-First-Search algorithm application. Here’s an example solution:</p><pre>function Traverse(p_element,p_callback) {<br>   p_callback(p_element);<br>   var list = p_element.children;<br>   for (var i = 0; i &lt; list.length; i++) {<br>       Traverse(list[i],p_callback);  // recursive call<br>   }<br>}</pre><h4>3. What will the following code output and why?</h4><pre>var b = 1;<br>function outer(){<br>   	var b = 2<br>    function inner(){<br>        b++;<br>        var b = 3;<br>        console.log(b)<br>    }<br>    inner();<br>}<br>outer();</pre><p><strong>Answer:<br></strong>Output to the console will be “3”.</p><p>There are three closures in the example, each with it’s own<strong><em> var b</em></strong> declaration. When a variable is invoked closures will be checked in order from local to global until an instance is found. Since the <strong><em>inner </em></strong>closure has a <strong><em>b</em></strong> variable of its own, that is what will be output.</p><p>Furthermore, due to hoisting the code in inner will be interpreted as follows:</p><pre>function inner () {<br>    var b; // b is undefined<br>    b++; // b is NaN<br>    b = 3; // b is 3<br>    console.log(b); // output &quot;3&quot;<br>}</pre><h4>4. <strong>What is </strong><strong>WeakMap in ES6?</strong></h4><p><strong>Answer:<br></strong>The <strong><em>WeakMap </em></strong>is same as <strong><em>Map</em></strong> where it is a collection of key/value pairs. But in <strong><em>WeakMap</em></strong>, the <strong>keys must be objects</strong> and the values can be arbitrary values. The object references in the keys are held weakly, meaning that they are a target of garbage collection (GC) if there is no other reference to the object anymore. The <strong><em>WeakMap </em></strong>API is the same as the <strong><em>Map</em></strong> API.</p><p>However, One difference to Map objects is that WeakMap keys are not enumerable. And there are no methods giving us a list of keys. If they were, the list would depend on the state of garbage collection, introducing non-determinism. If we want to have a list of keys, we should use a <strong><em>Map</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/0*--Vd8knpQnW3drWp.png" /></figure><h4><strong>5. What is </strong><strong>Set?</strong></h4><p><strong>Answer:<br><em>Set </em></strong>objects are collections of unique values. Duplicate values are ignored, as the collection must have all unique values. The values can be primitive types or object references.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/0*4enZqMvvgqvLB1Cx.png" /></figure><p>Also, <strong><em>NaN </em></strong>and <strong><em>undefined </em></strong>can also be stored in a <strong><em>Set</em></strong>. <strong><em>NaN </em></strong>is considered the same as <strong><em>NaN </em></strong>(even though <strong><em>NaN !== NaN</em></strong>).</p><h4>6. <strong>What is Generator function?</strong></h4><p><strong>Answer:<br></strong>Generator functions are a new feature in ES6 that allow a function to generate many values over time by returning an object which can be iterated over to pull values from the function one value at a time.</p><p>A generator function returns an <strong>iterable object</strong> when it’s called. It is written using the new * syntax as well as the new yield keyword introduced in ES6.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/0*MSUI9Vgah0E1v3D4.png" /></figure><p>Each time yield is called, the yielded value becomes the next value in the sequence. Also, note that generators compute their yielded values on demand, which allows them to efficiently represent sequences that are expensive to compute, or even infinite sequences.</p><h4>7. <strong>What is </strong><strong>WeakSet?</strong></h4><p><strong>Answer:<br></strong>The <strong><em>WeakSet </em></strong>object lets you store weakly held objects in a collection.</p><p><strong><em>WeakSet </em></strong>objects are collections of objects. An object in the <strong><em>WeakSet </em></strong>may occur only once; it is unique in the <strong><em>WeakSet</em></strong>’s<strong><em> </em></strong>collection. The main differences to the <strong><em>Set </em></strong>object are:</p><ul><li>Unlike <strong><em>Set</em></strong>, <strong><em>WeakSet </em></strong>s are collections of <strong>objects only</strong> and not of arbitrary values of any type.</li><li>The <strong><em>WeakSet </em></strong>is weak: References to objects in the collection are held weakly. If there is no other reference to an object stored in the <strong><em>WeakSet</em></strong>, they can be garbage collected. That also means that there is no list of current objects stored in the collection. WeakSets are not enumerable.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/0*rDYJ7RGdILdO5_Y9.png" /></figure><h4>8. What is undefined x 1 in JavaScript?</h4><p><strong>Answer:</strong></p><pre><strong>var</strong> trees = [&quot;redwood&quot;,&quot;bay&quot;,&quot;cedar&quot;,&quot;oak&quot;,&quot;maple&quot;];<br><strong>delete</strong> trees[3];</pre><p>When you run the code above and type<strong><em> console.log(trees); </em></strong>into your Chrome developer console, you will get<br><strong><em>[“redwood”, “bay”, “cedar”, undefined × 1, “maple”]</em></strong>. When you run the code in Firefox&#39;s browser console, you will get <strong><em>[“redwood”, “bay”, “cedar”, undefined, “maple”]</em></strong>. Thus, it&#39;s clear that the Chrome browser has its own way of displaying uninitialised indexes in arrays. However, when you check <strong><em>trees[3] === undefined</em></strong> in both browsers, you will get similar output as <strong><em>true</em></strong>.</p><p>Note: Please remember you do not need to check for the uninitialised index of array in <strong><em>trees[3] === ‘undefined × 1’</em></strong>, as it will give you an error. <strong><em>‘undefined × 1’ </em></strong>is just way of displaying an array&#39;s uninitialised index in Chrome.</p><h4>9. What is function hoisting in JavaScript?</h4><p><strong>Answer:<br></strong>Function Expression</p><pre><strong>var</strong> foo = <strong>function</strong> <strong>foo</strong>(){ <br> 	<strong>return</strong> 12; <br>};</pre><p>In JavaScript, variable and functions are <strong><em>hoisted</em></strong>. Let&#39;s take function <strong><em>hoisting </em></strong>first. Basically, the JavaScript interpreter looks ahead to find all variable declarations and then hoists them to the top of the function where they&#39;re declared. For example:</p><pre>foo(); <em>// Here foo is still undefined </em><br><strong>var</strong> foo = <strong>function</strong> <strong>foo</strong>(){ <br> 	<strong>return</strong> 12; <br>};</pre><p>Behind the scene of the code above looks like this:</p><pre><strong>var</strong> foo = undefined;<br>    foo(); <em>// Here foo is undefined </em><br> 	   foo = <strong>function</strong> <strong>foo</strong>(){<br> 	      / Some code stuff<br>      }</pre><pre><strong>var</strong> foo = undefined;<br> 	 foo = <strong>function</strong> <strong>foo</strong>(){<br> 	     / Some code stuff<br>    }<br>    foo(); <em>// Now foo is defined here</em></pre><h4>10. What is the instanceof operator in JavaScript? What would be the output of the code below?</h4><pre><strong>function</strong> <strong>foo</strong>(){ <br>  <strong>return</strong> foo; <br>}<br><strong>new</strong> foo() <strong>instanceof</strong> foo;</pre><p><strong>Answer:</strong><br>Here, <strong><em>instanceof </em></strong>operator checks the current object and returns true if the object is of the specified type.</p><p>For Example:</p><pre><strong>var</strong> dog = <strong>new</strong> Animal();<br>dog <strong>instanceof</strong> Animal <em>// Output : true</em></pre><p>Here <strong><em>dog instanceof Animal</em></strong> is true since <strong><em>dog </em></strong>inherits from <strong><em>Animal.prototype</em></strong>.</p><pre><strong>var</strong> name = <strong>new</strong> String(&quot;xyz&quot;);<br>name <strong>instanceof</strong> String <em>// Output : true</em></pre><p>Here <strong><em>name instanceof String</em></strong> is true since <strong><em>name </em></strong>inherits from <strong><em>String.prototype.</em></strong> Now let&#39;s understand the code below:</p><pre><strong>function</strong> <strong>foo</strong>(){ <br>  <strong>return</strong> foo; <br>}<br><strong>new</strong> foo() <strong>instanceof</strong> foo;</pre><p>Here function <strong><em>foo </em></strong>is returning <strong><em>foo</em></strong>, which again points to function <strong><em>foo</em></strong>.</p><pre><strong>function</strong> <strong>foo</strong>(){<br>  <strong>return</strong> foo; <br>}<br><strong>var</strong> bar = <strong>new</strong> foo();<br><em>// here bar is pointer to function foo(){return foo}.</em></pre><p>So the <strong><em>new foo() instanceof foo</em></strong> return <strong><em>false;</em></strong></p><p><strong>That’s all for today…Thank for Reading. Give a clap if you liked this article. Happy Learning :)</strong></p><p><strong><em>Article Reference:</em></strong></p><p><a href="https://www.toptal.com/javascript/interview-questions?fbclid=IwAR1P_oo9G9kU5r8zDFCtuVq5fS4_wYVLTu7c_-yfO4wFhaM7kbP1isVEmX0"><em>https://www.toptal.com/javascript/interview-questions</em></a></p><p><a href="https://medium.com/@vigowebs/frequently-asked-es6-interview-questions-and-answers-e3fb7f2dba2"><em>https://medium.com/@vigowebs/frequently-asked-es6-interview-questions-and-answers-e3fb7f2dba2</em></a></p><p><a href="https://www.codementor.io/@nihantanu/21-essential-javascript-tech-interview-practice-questions-answers-du107p62z"><em>https://www.codementor.io/@nihantanu/21-essential-javascript-tech-interview-practice-questions-answers-du107p62z</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c6990f9256c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Interview Questions (Part-1)]]></title>
            <link>https://medium.com/@rbiswas596/javascript-interview-questions-part-1-1187eca12235?source=rss-8499b6585dc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/1187eca12235</guid>
            <dc:creator><![CDATA[Rahul Biswas]]></dc:creator>
            <pubDate>Tue, 12 May 2020 17:59:14 GMT</pubDate>
            <atom:updated>2020-05-12T17:59:14.742Z</atom:updated>
            <content:encoded><![CDATA[<h4>Milestone 3 (Day 2)</h4><h4>1. difference between Function.prototype.apply and Function.prototype.call?</h4><p>The only difference between apply and call is how we pass the arguments in the function being called. In apply we pass the arguments as an array and in call we pass the arguments directly in the argument list.</p><p><strong>Example:</strong></p><blockquote>const obj1 = {<br> result:0<br>};</blockquote><blockquote>const obj2 = {<br> result:0<br>};</blockquote><blockquote>function reduceAdd(){<br> let result = 0;<br> for(let i = 0, len = arguments.length; i &lt; len; i++){<br> result += arguments[i];<br> }<br> this.result = result;<br>}</blockquote><blockquote>reduceAdd.apply(obj1, [1, 2, 3, 4, 5]); // returns 15<br>reduceAdd.call(obj2, 1, 2, 3, 4, 5); // returns 15</blockquote><h4>2. How to check if a value is an Array?</h4><p>We can check if a value is an Array by using the Array.isArray method available from the Array global object. It returns true when the parameter pass to it is an Array otherwise false.</p><p><strong>Example:</strong></p><blockquote>console.log(Array.isArray(5)); // false<br>console.log(Array.isArray(“”)); // false<br>console.log(Array.isArray()); // false<br>console.log(Array.isArray(null)); // false<br>console.log(Array.isArray({ length: 5 })); // false<br>console.log(Array.isArray([])); // true</blockquote><h4>3. What is the Set object and how does it work?</h4><p>The Set object is an ES6 feature that lets you store unique values, primitives or object references. A value in a Set can only occur once. It checks if a value exists in the set object using the SameValueZero algorithm.</p><p>We can make Set instance using Set constructor and we can optionally pass an Iterable as the initial value.</p><p><strong>Example:</strong></p><blockquote>const set1 = new Set();<br>const set2 = new Set([“a”,”b”,”c”,”d”,”d”,”e”]);</blockquote><p><strong>Note</strong>: We can add, remove, check or get the length of the value into the Set instance.</p><h4>4. The fastest way in converting a string to a number</h4><p>According to MDN Documentation, the “<strong><em>+</em></strong>” operator is the fastest way of converting a string to a number because it does not perform any operations on the value if it is already a number.</p><h4>5. difference between the in operator and the hasOwnProperty method in objects?</h4><p>Both of these features check if a property exists in an object. It will return true-false. The difference is the <strong><em>in </em></strong>operator also checks the objects’ <strong><em>Prototype Chain</em></strong> if the property was not found in the current object while the hasOwnProperty method just checks if the property exists in the current object ignoring the Prototype Chain.</p><p><strong>Example:</strong></p><blockquote>console.log(“prop” in o); // true;<br>console.log(“toString” in o); // true, the toString method is available in this object’s prototype which is the Object.prototype</blockquote><blockquote>console.log(o.hasOwnProperty(“prop”)); // true<br>console.log(o.hasOwnProperty(“toString”)); // false, does not check the object’s prototype</blockquote><h4>6. monolithic and microservice architectures</h4><p><strong>Monolithic Architectures: <br></strong>If the app is written as a single cohesive unit of code whose components are designed to work together, sharing the same memory space and resources, is called Monolithic architecture.</p><p><strong>Microservice Architectures:<br></strong>If the app is made up of lots of smaller, independent applications capable of running in their own memory space and scaling independently from each other across potentially many separate machines.</p><blockquote>Netflix, eBay, Amazon, the UK Government Digital Service, Twitter, PayPal, The Guardian, and many other large-scale websites and applications have all evolved from monolithic to microservices architecture</blockquote><h4>7. Event Delegate - destroy multiple list items with one click handler?</h4><p>To handle similar events in an enormous list of items, we can use event handler as many times as we need, like copying and pasting. But this would not be an efficient solution because a change in one place will bear you to bound multiple changes &amp; that would be horrible for thousands of items.<br>But if we use Event Delegation in JavaScript, which is leveraging the event bubbler. Rather than using the event handler in every child element, it would be subtle to declare the event handler in the parent element. This is known as Event Delegation.<br><br><strong>Example:</strong></p><blockquote>&lt;ul id=”listToDestroy”&gt;<br> &lt;li&gt;&lt;a href=”#”&gt;first item&lt;/a&gt;&lt;/li&gt;<br> &lt;li&gt;&lt;a href=”#”&gt;second item&lt;/a&gt;&lt;/li&gt;<br> &lt;li&gt;&lt;a href=”#”&gt;third item&lt;/a&gt;&lt;/li&gt;<br> &lt;li&gt;&lt;a href=”#”&gt;forth item&lt;/a&gt;&lt;/li&gt;<br> &lt;li&gt;&lt;a href=”#”&gt;Fifth item&lt;/a&gt;&lt;/li&gt;<br>&lt;/ul&gt;</blockquote><blockquote>document.getElementById(‘listToDestroy’).addEventListener(‘click’, function (e) { <br> var elm = e.target.parentNode; <br> elm.parentNode.removeChild(elm);<br> e.preventDefault();<br>});</blockquote><h4>8. What is the arguments object?</h4><p>A collection of parameter values pass in a function.</p><p>It’s an -<br>i) Array-like object, <br>ii) has a length property <br>iii) we can access individual values using array indexing notation <br><strong>Note:</strong> Arguments object does not have the built-in methods in an array forEach, reduce, filter and map.</p><p>We can convert the arguments object into an array using the</p><blockquote>Array.prototype.slice.<br>function one() {<br> return Array.prototype.slice.call(arguments);<br>}</blockquote><p><strong>Note:</strong> the arguments object does not work on ES6 arrow functions.</p><blockquote>function one() {<br> return arguments;<br>}<br>const two = function () {<br> return arguments;<br>}<br>const three = function three() {<br> return arguments;<br>}</blockquote><blockquote>const four = () =&gt; arguments;</blockquote><blockquote>four(); // Throws an error — arguments is not defined</blockquote><p>When we invoke the function four it throws a ReferenceError: arguments is not defined error. We can solve this problem if your envinroment supports the rest syntax.</p><blockquote>const four = (…args) =&gt; args;</blockquote><p>This puts all parameter values in an array automatically.</p><h4>9. How to create an object without a prototype?</h4><p>We can create an object without a prototype using the Object.create method.</p><p><strong>Example:</strong></p><blockquote>const o1 = {};<br> console.log(o1.toString()); <br> // logs [object Object] get this method to the Object.prototype</blockquote><blockquote>const o2 = Object.create(null);<br> // the first parameter is the prototype of the object “o2” which in this<br> // case will be null specifying we don’t want any prototype<br> console.log(o2.toString());<br> // throws an error o2.toString is not a function</blockquote><h4>10. What does “use strict” do?</h4><p>“use strict” is a ES5 feature in JavaScript that makes our code in Strict Mode in functions or entire scripts. Strict Mode helps us avoid bugs early on in our code and adds restrictions to it.</p><p><strong>Strict Mode</strong> allows us the following restrictions:</p><p>i) Assigning or Accessing a variable that is not declared</p><blockquote>function returnY(){<br> “use strict”;<br> y = 123;<br> return y;<br> }</blockquote><p>ii) Deleting an undeletable property</p><blockquote>“use strict”;<br> const obj = {};</blockquote><blockquote>Object.defineProperty(obj, ‘x’, {<br> value : ‘1’<br> });</blockquote><blockquote>delete obj.x;</blockquote><p>iii) Duplicate parameter names</p><blockquote>“use strict”;</blockquote><blockquote>function someFunc(a, b, b, c){ }</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1187eca12235" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[60 HTML & CSS Interview Questions]]></title>
            <link>https://medium.com/@rbiswas596/60-html-css-interview-questions-1bd56388bf35?source=rss-8499b6585dc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/1bd56388bf35</guid>
            <dc:creator><![CDATA[Rahul Biswas]]></dc:creator>
            <pubDate>Mon, 11 May 2020 17:59:51 GMT</pubDate>
            <atom:updated>2020-05-11T17:59:51.057Z</atom:updated>
            <content:encoded><![CDATA[<h3>Some Common Interview Questions for HTML-CSS that every web developer should know</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*k3V3xEuLvX33uEHQYQKkkw.png" /></figure><h3>HTML Question (1–30)</h3><h4>1. What is HTML5 Web Storage?</h4><p>HTML5 Web Storage, also known as DOM Storage is a way to preserve state on either the client or server which makes it much easier to work against the stateless nature of HTTP. It allows the web pages to store the data locally in the user’s browser.</p><p>Following are the advantages of HTML5 Web Storage.</p><ul><li>It can store 5 to 10 MB data. That is far more than what cookies allow.</li><li>HTML5 never transfers Web storage data with any HTTP request. Thus creating less overhead than cookies and in turn, increase the performance of the application.</li><li>Apps can work both online and offline.</li><li>This API is easy to learn and use.</li></ul><h4>2. What is the need of introducing Local Storage in HTML5?</h4><p>Before HTML5, LocalStores was done with Cookies. They are not very good for large amounts of data, because, with every request, it passes this data to the server, making it very slow and ineffective. However, HTML5 does not pass this data on every server request. It uses the data ONLY when required. In HTML5, it is possible to store large amounts of data without affecting the website’s performance. Data for different website gets stored in separate areas. However, a particular website can only access its own data.</p><h4>3. key differences between localStorage and sessionStorage objects?</h4><p>Following are the key differences between localStorage and sessionStorage objects.</p><ul><li>The localStorage object stores the data without an expiry date. However, sessionStorage object stores the data for only one session.</li><li>In the case of a localStorage object, data will not delete when the browser window closes. However, the data gets deleted, if the browser window closes, in the case of sessionStorage objects.</li><li>The data in sessionStorage is accessible only in the current window of the browser. But the data in the localStorage can be shared between multiple windows of the browser.</li></ul><h4>4. What is a Manifest file?</h4><p>A Manifest file is a simple text file, that tells the browser what to cache and what not to cache.</p><p>A Manifest file contains three Sections as</p><ul><li>CACHE MANIFEST — HTML5 performs the caching of files listed under this section after<br>they get downloaded for the first time.</li><li>NETWORK — Files listed here, always need a connection to the server. The browser can never cache them.</li><li>FALLBACK — Files listed here specify the fallback pages, if any page in it is not accessible.</li></ul><h4>5. When is it appropriate to use frames?</h4><p>Frames can make navigating a site much easier. If the main links to the site are located in a <strong>frame</strong> that appears at the top or along the edge of the browser, the content for those links can be displayed in the <strong>remainder</strong> of the browser window.</p><h4>6. How do you create text on a webpage that allows you to send an email when clicked?</h4><p>To change the text into a clickable link to send an email, you need to use the <em>mailto</em> command within the <em>href</em> tag. You can write it in the following way:</p><blockquote><strong>&lt;a href=”mailto:youremailaddress”&gt;text to be clicked&lt;/a&gt;</strong></blockquote><h4>7. What’s the difference between a block-level element and an inline element?</h4><p>Each element in HTML is displayed in one of a few ways. By default, most tags are either displayed as block-level or inline. This value can be overridden using <a href="https://www.goskills.com/Course/Intro-CSS">CSS</a>.</p><p><strong>Block<br></strong>As the name suggests, a block-level element is drawn as a block that stretches to fill the full width available to it (the width of its container) and will always start on a new line.</p><p>Examples of elements that are block-level by default: <em>&lt;div&gt;, &lt;img&gt;, &lt;section&gt;, &lt;form&gt;, &lt;nav&gt;</em>.</p><p><strong>Inline<br></strong>Unlike the block-level elements, inline elements are drawn where they are defined and only take up space that is absolutely needed. The easiest way to understand how they work is to look at how text flows on a page. When a line of text gets to the end of the space available, it wraps onto the next line and happily keeps going. If you were to tack more text onto an existing line of text, it will stay on the same line, as if it was all part of the same text to begin with.</p><p>Examples of elements that are inline by default: <em>&lt;span&gt;, &lt;b&gt;, &lt;strong&gt;, &lt;a&gt;, &lt;input&gt;</em>.</p><h4>8. What are “web workers”?</h4><p>Web workers at long last bring multi-threading to JavaScript.</p><p>A web worker is a script that runs in the background (i.e., in another thread) without the page needing to wait for it to complete. The user can continue to interact with the page while the web worker runs in the background. Workers utilize thread-like message passing to achieve parallelism.</p><h4>9. What is semantic HTML?</h4><p>Semantic HTML is a coding style. It is the use of <strong>HTML markup</strong> to reinforce the semantics or meaning of the content. For example: In semantic HTML <strong>&lt;b&gt; &lt;/b&gt;</strong> tag is not used for bold statement as well as <strong>&lt;i&gt; &lt;/i&gt;</strong> tag is used for italic. Instead of these we use <strong>&lt;strong&gt;&lt;/strong&gt;</strong> and <strong>&lt;em&gt;&lt;/em&gt;</strong> tags.</p><h4>10. What are some of the key new features in HTML5?</h4><p>Key new features of HTML5 include:</p><p>Improved support for embedding graphics, audio, and video content via the new <em>&lt;canvas&gt;, &lt;audio&gt;, and &lt;video&gt;</em> tags.</p><p>Extensions to the JavaScript API such as geolocation and drag-and-drop as well for storage and caching.</p><p>Introduction of “web workers”.</p><p>Several new semantic tags were also added to complement the structural logic of modern web applications. These include the <em>&lt;main&gt;, &lt;nav&gt;, &lt;article&gt;, &lt;section&gt;, &lt;header&gt;, &lt;footer&gt;</em>, and <em>&lt;aside&gt;</em> tags.</p><p>New form controls, such as <em>&lt;calendar&gt;, &lt;date&gt;, &lt;time&gt;, &lt;email&gt;, &lt;url&gt;</em>, and <em>&lt;search&gt;</em>.</p><h4>11. What is the Geolocation API in HTML5?</h4><p>HTML5’s Geolocation API lets users share their physical location with chosen web sites. JavaScript can capture a user’s latitude and longitude and can send it to the back-end web server to enable location-aware features like finding local businesses or showing their location on a map.</p><p>Today, most browsers and mobile devices support the Geolocation API. The Geolocation API works with a new property of the global <strong><em>navigator </em></strong>object.</p><p>A Geolocation object can be created as follows:</p><blockquote><strong>var geolocation = navigator.geolocation;</strong></blockquote><p>The <strong><em>geolocation </em></strong>object is a service object that allows widgets to retrieve information about the geographic location of the user’s device.</p><h4>12. Describe the relationship between the &lt;header&gt; and &lt;h1&gt; tags in HTML5.</h4><p>In previous specifications of HTML, only one <em>&lt;h1&gt;</em> element was typically present on a page, used for the heading of the entire page. HTML5 specifies that <em>&lt;h1&gt;</em> represents the top-level heading of a <em>“section”</em>, whether that be the page <em>&lt;body&gt;</em>, or an <em>&lt;article&gt;</em> or <em>&lt;section&gt;</em> element. In fact, every <em>&lt;header&gt;</em> element should at least contain an <em>&lt;h1&gt;</em> element. If there is no natural heading for the section, it is a good indication it should not use an <em>&lt;article&gt;</em> or <em>&lt;section&gt;</em> tag.</p><h4>13. What’s the difference between the &lt;svg&gt; and &lt;canvas&gt; elements?</h4><p>The <em>&lt;svg&gt;</em> element is a container for SVG graphics. SVG has several methods for drawing paths, boxes, circles, text, and even bitmap images.</p><p>SVG is a language for describing 2D graphics, but <em>&lt;canvas&gt;</em> allows you to draw 2D graphics on the fly using JavaScript.</p><p>SVG is XML-based, which means that every element is available within the SVG DOM. You can attach JavaScript event handlers for an element.</p><p>In SVG, each drawn shape is remembered as an object. If attributes of an SVG object are changed, the browser can automatically re-render the shape.</p><p>Canvas is rendered pixel by pixel. In canvas, once the graphic is drawn, it is forgotten by the browser. If its position should be changed, the entire scene needs to be redrawn, including any objects that might have been covered by the graphic.</p><h4>14. What is the use of data- attribute?</h4><p>It allows us to store extra information/data in the DOM.</p><p><strong>Advantages of using data-*<br></strong>i) valid html with embedded private data can be written<br>ii) data attributes are easily accessible by javascript</p><blockquote>&lt;div id=“myDiv” data-user=“username” data-list-size=“7” data-maxage=“80”&gt;&lt;/div&gt;</blockquote><h4>15. How can u generate public key in html?</h4><p>The HTML <em>&lt;keygen&gt;</em> element exists to facilitate generation of key material, and submission of the public key as part of an HTML form.</p><p><strong><em>Note: It has to be used inside a form element</em></strong></p><blockquote>&lt;keygen name=”name” challenge=”challenge string” keytype=”type” keyparams=”pqg-params”&gt;</blockquote><h4>16. HTML download order</h4><p><strong>Does style1.css have to be downloaded and parsed before style2.css can be fetched?</strong></p><blockquote>&lt;head&gt;<br> &lt;link href=”style1.css” rel=”stylesheet”&gt;<br> &lt;link href=”style2.css” rel=”stylesheet”&gt;<br>&lt;/head&gt;</blockquote><p><strong>Answer: </strong>No</p><p><strong>Does style2.css have to be downloaded and parsed before Paragraph 1 is rendered on the page?</strong></p><blockquote>&lt;head&gt;<br> &lt;link href=”style1.css” rel=”stylesheet”&gt;<br>&lt;/head&gt;</blockquote><blockquote>&lt;body&gt;<br> &lt;p&gt;Paragraph 1&lt;/p&gt;<br> &lt;p&gt;Paragraph 2&lt;/p&gt;<br> &lt;link href=”style2.css” rel=”stylesheet”&gt;<br>&lt;/body&gt;</blockquote><p><strong>Answer:</strong> Yes</p><h4>17. What is difference between HTML and XHTML?</h4><p>The differences between HTML and XHTML are:</p><ul><li>HTML is an application of Standard Generalized Markup Language. Whereas, XML is an application of Extensible Markup Language.</li><li>The first one is a static Web Page whereas the later one is a dynamic Web Page.</li><li>HTML allows programmer to perform changes in the tags and use attribute minimization whereas XHTML when user need a new markup tag then user can define it in this.</li><li>HTML is about displaying information whereas XHTML is about describing the information.</li></ul><h4>18. What are logical and physical tags in HTML?</h4><p><strong>Logical tags</strong> are used to tell the meaning of the enclosed text. The example of the logical tag is <strong><em>&lt;strong&gt; &lt;/strong&gt;</em></strong> tag. When we enclose the text in the strong tag, it tells the browser that enclosed text is more important than other texts.</p><p><strong>Physical tags</strong> are used to tell the browser how to display the text enclosed in the physical tag. Some of the examples of physical tags are <strong><em>&lt;b&gt;, &lt;big&gt;, &lt;i&gt;</em>.</strong></p><h4>19. What is the use of an iframe tag?</h4><p>An iframe is used to display a web page within a web page.</p><p><strong>Syntax:</strong></p><blockquote>&lt;iframe src=”URL”&gt;&lt;/iframe&gt;</blockquote><p><strong>Example:</strong></p><blockquote>&lt;iframe src=”demo_iframe.html” width=”200px” height=”200px”&gt;&lt;/iframe&gt;</blockquote><p><strong>Target to a link:</strong></p><blockquote>&lt;iframe src=”<a href="http://www.edureka.co/">http://www.medium.co</a>m&quot; name=”iframe_a”&gt;&lt;/iframe&gt;</blockquote><h4>20. What are the entities in HTML?</h4><p>The HTML character entities are used as a replacement for reserved characters in HTML. You can also replace characters that are not present on your keyboard by entities. These characters are replaced because some characters are reserved in HTML.</p><h4>21. Is the &lt;!DOCTYPE html&gt; tag considered as a HTML tag?</h4><p>No, the &lt;!DOCTYPE html&gt; declaration is not an HTML tag.</p><p>There are many type of HTML, such as, HTML 4.01 Strict, HTML 4.01 Transitional, HTML 4.01 Frameset, XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1 etc. So, &lt;!DOCTYPE html&gt; is used to instruct the web browser about the HTML page.</p><h4>22. What is an image map?</h4><p>With HTML image-maps, you can create clickable areas on an image.</p><p>The <em>&lt;map&gt; </em>tag defines an image-map. An image-map is an image with clickable areas.</p><p>This tag facilitates us to link many different web pages using a single image. We can define shapes in images that we want to make part of an image mapping.</p><h4>23. What is the purpose of using alternative texts in image map?</h4><p>The purpose of using alternative texts is to define what the image is about. During an image mapping, it can be confusing and difficult to understand what hotspots correspond to a particular link. These alternative texts come in action here and put a description at each link which makes it easy for users to understand the hotspot links easily.</p><h4>24. What is the difference between progress and meter tag?</h4><p>The progress tag is used to represent the progress of the task only while the meter tag is used to measure data within a given range.</p><h4>25. Can we modify the attribute’s value of the HTML tag dynamically?</h4><p>Yes, we can modify the value of the attributes by using JavaScript.</p><p>Below is the input element whose attribute will be modified from text to password, JS code to modify the attribute value:</p><blockquote>&lt;input type=“text” id=“inputField”&gt;<br>document.getElementById(“inputField”).attr(“type”, “password”);</blockquote><h4>26. If the user’s operating system does not support the needed character, how can the symbol be represented?</h4><p>In cases wherein their operating system does not support a particular character, it is still possible to display that character by showing it as an image instead.</p><h4>27. How do you change the number type in the middle of a list?</h4><p>The &lt;li&gt; tag includes two attributes — type and value. The type attribute can be used to change the numbering type for any list item. The value attribute can change the number index.</p><h4>28. What are the different new form element types in HTML 5?</h4><p>Following is a list of 10 frequently used new elements in HTML 5:</p><ul><li>Color</li><li>Date</li><li>Datetime-local</li><li>Email</li><li>Time</li><li>Url</li><li>Range</li><li>Telephone</li><li>Number</li><li>Search</li></ul><h4>29. What is the use of figure tag in HTML 5?</h4><p>The figure tag is used to add a photo in the document on the web page. It is used to handle the group of diagrams, photos, code listing with some embedded content.</p><blockquote>&lt;h1&gt;The figure and figcaption element&lt;/h1&gt;</blockquote><blockquote>&lt;figure&gt;<br> &lt;img src=”pic_trulli.jpg” alt=”Trulli” style=”width:100%”&gt;<br> &lt;figcaption&gt;Fig.1 — Trulli, Puglia, Italy.&lt;/figcaption&gt;<br>&lt;/figure&gt;</blockquote><h4>30. What is the difference between HTML5 Application cache and regular HTML browser cache?</h4><p>Following are the key differences between the HTML5 Application cache and regular HTML browser cache:</p><blockquote>Application Cache can prefetch pages that have not been visited at all and are thereby unavailable in the regular browser cache. However, the browser cache will only store the pages (and associated assets) the user has visited actually.</blockquote><blockquote>The AppCache allows web apps (and websites) to be made available offline, that too, with the same speed benefits as the regular browser cache could provide only when the user is online.</blockquote><h3>CSS Question (31–60)</h3><h4>31. Explain the CSS “box model” and the layout components that it consists of. Provide some usage examples.</h4><p><strong>Answer:<br></strong>The CSS box model is a rectangular layout paradigm for HTML elements that consists of the following:</p><ul><li>Content — The content of the box, where text and images appear</li><li>Padding — A transparent area surrounding the content (i.e., the amount of space between the border and the content)</li><li>Border — A border surrounding the padding (if any) and content</li><li>Margin — A transparent area surrounding the border (i.e., the amount of space between the border and any neighboring elements)</li></ul><p>Each of these properties can be specified independently for each side of the element (i.e., top, right, bottom, left) or fewer values can be specified to apply to multiple sides. For example:</p><blockquote>/* top right bottom left */<br>padding: 25px 50px 75px 100px;</blockquote><blockquote>/* same padding on all 4 sides: */<br>padding: 25px;</blockquote><blockquote>/* top/bottom padding 25px; right/left padding 50px */<br>padding: 25px 50px;</blockquote><blockquote>/* top padding 25px; right/left padding 50px; bottom padding 75px */<br>padding: 25px 50px 75px;</blockquote><h4>32. Explain what elements will match each of the following CSS selectors:</h4><h4>div, p<br>div p<br>div &gt; p<br>div + p<br>div ~ p</h4><p><strong>Answer:<br></strong>div, p — Selects all &lt;div&gt; elements and all &lt;p&gt; elements</p><p>div p — Selects all &lt;p&gt; elements that are anywhere inside a &lt;div&gt; element</p><p>div &gt; p — Selects all &lt;p&gt; elements where the immediate parent is a &lt;div&gt; element</p><p>div + p — Selects all &lt;p&gt; elements that are placed immediately after a &lt;div&gt; element</p><p>div ~ p — Selects all &lt;p&gt; elements that are anywhere preceded by a &lt;div&gt; element</p><h4>33. Explain the meaning of each of these CSS units for expressing length:</h4><h4>cm<br>em<br>in<br>mm<br>pc<br>pt<br>px</h4><p><strong>Answer:<br></strong>cm — centimeters</p><ul><li>em — elements (i.e., relative to the font-size of the element; e.g., 2 em means 2 times the current font size)</li><li>in — inches</li><li>mm — millimeters</li><li>pc — picas (1 pc = 12 pt = 1/6th of an inch)</li><li>pt — points (1 pt = 1/72nd of an inch)</li><li>px — pixels (1 px = 1/96th of an inch)</li></ul><h4>34. In CSS3, how would you select:</h4><h4>Every &lt;a&gt; element whose href attribute value begins with “https”.</h4><h4>Every &lt;a&gt; element whose href attribute value ends with “.pdf”.</h4><h4>Every &lt;a&gt; element whose href attribute value contains the substring “css”.</h4><p><strong>Answer:</strong></p><p>Select every &lt;a&gt; element whose href attribute value begins with “https”:</p><blockquote>a[href^=”https”]</blockquote><p>Select every &lt;a&gt; element whose href attribute value ends with “.pdf”:</p><blockquote>a[href$=”.pdf”]</blockquote><p>Select every &lt;a&gt; element whose href attribute value contains the substring “css”:</p><blockquote>a[href*=”css”]</blockquote><h4>35. Given the following HTML:</h4><pre>&lt;div id=&quot;page&quot;&gt;<br>  &lt;h1&gt;Heading Title&lt;/h1&gt;<br>  &lt;h2&gt;Subheading Title&lt;/h2&gt;<br>  &lt;h2&gt;Subheading Title&lt;/h2&gt;<br>  &lt;h1&gt;Heading Title&lt;/h1&gt;<br>  &lt;h2&gt;Subheading Title&lt;/h2&gt;<br>  &lt;h1&gt;Heading Title&lt;/h1&gt;<br>&lt;/div&gt;</pre><h4>How could you use CSS to achieve the following automatic numbering:</h4><p><strong>1) Heading Title</strong><br>1.1) Subheading Title<br>1.2) Subheading Title</p><p><strong>2) Heading Title</strong><br>2.1) Subheading Title</p><p><strong>3) Heading Title</strong></p><p><strong>Answer:<br></strong>The following CSS will achieve this type of automatic numbering:</p><blockquote>#page {<br> counter-reset: heading;<br>}</blockquote><blockquote>h1:before {<br> content: counter(heading)”) “;<br> counter-increment: heading;<br>}</blockquote><blockquote>h1 {<br> counter-reset: subheading;<br>}</blockquote><blockquote>h2:before {<br> content: counter(heading)”.” counter(subheading)”) “;<br> counter-increment: subheading;<br>}</blockquote><h4>36. Name all the modules which are used in the current version of CSS.</h4><p><strong>Answer: There are several modules in CSS as stated below:</strong></p><ul><li>Selectors</li><li>Box Model</li><li>Backgrounds and Borders</li><li>Text Effects</li><li>2D/3D Transformations</li><li>Animations</li><li>Multiple Column Layout</li><li>User Interface.</li></ul><h4>37. Distinguish between CSS2 and CSS3.</h4><p><strong>Answer: The differences between CSS2 and CSS3 are as follows:</strong></p><ul><li>CSS3 is divided into two various sections which are called a module. Whereas in CSS2 everything accedes into a single document with all the information in it.</li><li>CSS3 modules are supported almost on every browser and on the other hand modules of CSS and CSS2 are not supported in every browser.</li><li>In CSS3, we will find that many graphics related characteristics have been introduced like Border-radius or box-shadow, flexbox.</li><li>In CSS3, a user can precise multiple background images on a webpage by using properties like background-image, background-position, and background-repeat styles.</li></ul><h4>38. Explain the concept of Tweening.</h4><p><strong>Answer: <br></strong>Tweening is the process in which we create intermediate frames between two images to get the appearance of the first image which develops into the second image.</p><p>It is mainly used for creating animation.</p><h4>39. Define CSS image scripts.</h4><p><strong>Answer: <br></strong>CSS image scripts are a group of images that are placed into one image. It reduces the load time and request number to the server while projecting multiple images into a single web page.</p><h4>40. Explain the term Responsive web design.</h4><p><strong>Answer: <br></strong>It is a method in which we design and develop a web page according to the user activities and conditions which are based on various components like the size of the screen, portability of the web page on the different devices, etc. It is done by using different flexible layouts and grids.</p><h4>41. What are CSS counters?</h4><p><strong>Answer: <br></strong>CSS counters are variables that can be incremented by rules of CSS that inspector track how many times the variable has been used.</p><h4>42 What is CSS specificity?</h4><p><strong>Answer: <br></strong>CSS specificity is a score or rank that decides which style declaration has to be used to an element. (*) this universal selector has low specificity while ID selectors have high specificity.</p><p><strong>There are four categories in CSS which authorize the specificity level of the selector.</strong></p><ul><li>Inline style</li><li>IDs</li><li>Classes, Attributes, and pseudo-classes.</li><li>Elements and pseudo-elements.</li></ul><h4>43) How can we calculate specificity?</h4><p><strong>Answer: <br></strong>To calculate specificity we will start with 0, then we have to add 1000 for each ID and we have to add 10 to the attributes, classes or pseudo-classes with each element name or pseudo-element and later we have to add 1 to them.</p><p><strong>Example:</strong></p><blockquote>h2<br> #content h2<br> &lt;div id=”content”&gt;<br> &lt;h2 style=”color:#FF0000&quot;&gt;heading&lt;/h2&gt;<br> &lt;/div&gt;</blockquote><h4>44. What are gradients in CSS?</h4><p><strong>Answer: <br></strong>It is a property of CSS which allows you to display a smooth transformation between two or more than two specified colors.</p><p>There are two types of gradients that are present in CSS. <strong>They are:</strong></p><ul><li>Linear Gradient</li><li>Radial Gradient</li></ul><h4>45. What is CSS flexbox?</h4><p><strong>Answer: <br></strong>It allows you to design a flexible responsive layout structure without using any float or positioning property of CSS. To use CSS flexbox you need to define a flex container initially.</p><p><strong>Example:</strong></p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;</pre><pre>&lt;style&gt;<br>.flex-container {<br>  display: flex;<br>  background-color: #f4b042;<br>}</pre><pre>.flex-container &gt; div {<br>  background-color: #d60a33;<br>  margin: 10px;<br>  padding: 20px;<br>  font-size: 30px;<br>}</pre><pre>&lt;/style&gt;<br>&lt;/head&gt;</pre><pre>&lt;body&gt;<br>&lt;div class=&quot;flex-container&quot;&gt;<br>  &lt;div&gt;1&lt;/div&gt;<br>  &lt;div&gt;2&lt;/div&gt;<br>  &lt;div&gt;3&lt;/div&gt; <br>&lt;/div&gt;<br>&lt;p&gt; Example of  &lt;em&gt;flex&lt;/em&gt;box.&lt;/p&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*b2-YiCXugYESrshd3bXRZw.png" /></figure><h4>46. Write all the properties of the flexbox.</h4><p><strong>Answer:</strong> <br>There are several properties of the flexbox that are used in the HTML webpage.</p><p><strong>They are:</strong></p><ul><li>flex-direction</li><li>flex-wrap</li><li>flex-flow</li><li>justify-content</li><li>align-items</li><li>align-content</li></ul><h4>47. Rapid Fire</h4><p><strong>Question:</strong> Does css properties are case sensitive?</p><p><strong>Answer:</strong> no.</p><p><strong>Question:</strong> Why css selectors mixed up with cases don’t apply the styles?</p><p><strong>Answer:</strong> because, html ID and classes are case sensitive.</p><p><strong>Question:</strong> Does margin-top or margin-bottom has effect on inline element?</p><p><strong>Answer:</strong> no.</p><p><strong>Question:</strong> Does padding-top or padding-bottom has effect on inline element?</p><p><strong>Answer:</strong> no.</p><p><strong>Question:</strong> Does padding-left or padding-right or margin-left or margin-right has effect on inline element?</p><p><strong>Answer:</strong> yes.</p><p><strong>Question:</strong> If you have a &lt;p&gt; element with font-size: 10rem, will the text be responsive when the user resizes / drags the browser window?</p><p><strong>Answer:</strong> no.</p><p><strong>Question:</strong> The pseudo class :checked will select inputs with type radio or checkbox, but not &lt;option&gt; elements.</p><p><strong>Answer:</strong> False</p><p><strong>Question:</strong> In a HTML document, the pseudo class :root always refers to the &lt;html&gt; element.</p><p><strong>Answer:</strong> True</p><p><strong>Question:</strong> The translate() function can move the position of an element on the z-axis.</p><p><strong>Answer:</strong> False</p><h4>48. What are the advantages of CSS?</h4><p><strong>Answer:</strong></p><ul><li>Bandwidth</li><li>Site-wide consistency</li><li>Page reformatting</li><li>Accessibility</li><li>Content separated from presentation</li></ul><h4>49. What are the limitations of CSS?</h4><p><strong>Answer:</strong></p><ul><li>Ascending by selectors is not possible</li><li>Limitations of vertical control</li><li>No expressions</li><li>No column declaration</li><li>Pseudo-class not controlled by dynamic behavior</li><li>Rules, styles, targeting specific text not possible</li></ul><h4>50. What is a CSS selector?</h4><p><strong>Answer:<br></strong>It is a string that identifies the elements to which a particular declaration apply. It is also referred as a link between the HTML document and the style sheet. It is equivalent of HTML elements. There are several different types of selectors in CSS: -</p><ul><li>CSS Element Selector</li><li>CSS Id Selector</li><li>CSS Class Selector</li><li>CSS Universal Selector</li><li>CSS Group Selector</li></ul><h4>51. What is the z-index in CSS?</h4><p><strong>Answer:<br></strong>The z-index helps specify the stack order of positioned elements that may overlap one another. The z-index default value is zero and can take on either a positive or negative number.</p><p>An element with a higher z-index is always stacked above than a lower index.</p><p>Z-Index can take the following values:</p><ul><li><strong>Auto:</strong> Sets the stack order equal to its parents.</li><li><strong>Number:</strong> Orders the stack order.</li><li><strong>Initial:</strong> Sets this property to its default value (0).</li><li><strong>Inherit:</strong> Inherits this property from its parent element.</li></ul><h4>52. What are CSS Sprites?</h4><p><strong>Answer:<br></strong>CSS sprites combine multiple images into one single larger image. It is a commonly-used technique for icons (Gmail uses it). This is how you could implement it:</p><ol><li>Use a sprite generator that packs multiple images into one and generates the appropriate CSS for it.</li><li>Each image would have a corresponding CSS class with <em>background-image, background-position</em> and <em>background-size</em> properties defined.</li><li>To use that image, add the corresponding class to your element.</li></ol><h4>53. Mention a few benefits of using CSS Sprites.</h4><p>CSS sprites come with their own advantages. Here are a few of them –</p><ul><li>Reduce the number of HTTP requests for multiple images (only one single request is required per sprite sheet). But with HTTP2, loading multiple images is no longer much of an issue.</li><li>Advance downloading of assets that won’t be downloaded until needed, such as images that only appear upon <em>:hover </em>pseudo-states. Blinking wouldn’t be seen.</li></ul><h4>54. What are pseudo-elements in CSS?</h4><p>A CSS pseudo-element is a keyword added to a selector that lets you style a specific part of the selected element(s). They can be used for decoration (<em>:first-line, :first-letter)</em> or adding elements to the markup (combined with <em>content: …</em>) without having to modify the markup (<em>:before, :after</em>).</p><ul><li><em>:first-line </em>and :<em>first-letter</em> can be used to decorate text.</li><li>Triangular arrows in tooltips use <em>:before</em> and<em> :after</em>. This encourages separation of concerns because the triangle is considered a part of styling and not really the DOM. It’s not really possible to draw a triangle with just CSS styles without using an additional HTML element.</li></ul><h4>55. What are the different media types allowed by CSS?</h4><p>There are four types of @media properties (including <em>screen</em>):</p><ul><li><strong>all</strong> — for all media type devices</li><li><strong>print</strong> — for printers</li><li><strong>speech</strong> — for screenreaders that “reads” the page out loud</li><li><strong>screen</strong> — for computer screens, tablets, smart-phones etc.</li></ul><p>Here is an example of print-media type’s usage:</p><blockquote><a href="http://twitter.com/media">@media</a> print {<br>h1 {<br>background-color: yellow;<br>}<br>}</blockquote><h4>56. What is the overflow property in CSS used for?</h4><p>The overflow property specifies what should happen if content overflows an element’s box. This property specifies whether to clip content or to add scrollbars when an element’s content is too big to fit in a specified area. Below are the overflow options available in CSS –</p><blockquote>overflow: auto;</blockquote><blockquote>overflow: none;</blockquote><blockquote>overflow: scroll;</blockquote><blockquote>overflow: visible;</blockquote><h4>57. What is the property that is used for controlling image-scroll?</h4><p>The background-attachment property sets whether a background image scrolls with the rest of the page, or is fixed. Here is an example of a background-image that will not scroll with the page (fixed):</p><blockquote>body {<br> background-image: url(https://medium.com/%E2%80%9Cimg_tree.gif%E2%80%9D);<br> background-repeat: no-repeat;<br> background-attachment: fixed;<br>}</blockquote><h4>58. What is the difference between {visibility: hidden} and {display: none}?</h4><p>display:none means that the tag in question will not appear on the page at all (although you can still interact with it through the DOM). There will be no space allocated for it between the other tags.</p><p>visibility:hidden means that unlike display:none, the tag is not visible, but space is allocated for it on the page. The tag is rendered, it just isn’t seen on the page.</p><p><strong>Example:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*cK369rqLLMM36g6I-vD9uw.png" /></figure><h4>59. What are functions/mixins?</h4><p>Functions are blocks of code that return a single value of any Sass data type. A <strong>mixin</strong> is very similar to a function. The main difference between the two is that mixins output lines of Sass code that will compile directly into CSS styles, while functions return a value that can then become the value for a CSS property or become something that might be passed to another function or mixin.</p><h4>60. How does CSS work under the hood?</h4><p>When a browser displays a document, it must combine the document’s content with its style information. It processes the document in two stages:</p><ul><li>The browser converts <em>HTML</em> and <em>CSS</em> into the <em>DOM (Document Object Model)</em>. The DOM represents the document in the computer’s memory. It combines the document’s content with its style.</li><li>The browser displays the contents of the DOM.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j3e5AtKvHzh4HI8tzeJ_Mg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1bd56388bf35" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Week 2 - Summary of React & JS with Data Structures, Algorithms Learning]]></title>
            <link>https://medium.com/@rbiswas596/week-2-summary-of-react-js-with-data-structures-algorithms-learning-2785509ac06?source=rss-8499b6585dc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/2785509ac06</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[js]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Rahul Biswas]]></dc:creator>
            <pubDate>Sun, 10 May 2020 15:16:12 GMT</pubDate>
            <atom:updated>2020-05-10T15:16:12.827Z</atom:updated>
            <content:encoded><![CDATA[<h3>It’s Day 7 of React Learning - Milestone 2 Completion!</h3><p>Welcome to the learning path of React and JavaScript. This is a summary of what we have learned about the React (one of the most popular front-end JS library), Basic Data Structures, Algorithms of JavaScript in the last six consecutive days. We’ve briefly revised here some of the important and major topics of React such as How React works behind the scene, Virtual DOM, JSX, State, Props, Hooks, Unit Testing, Error Handling, Web Accessibility, React Higher-Order Components (HOC), React Component Lifecycle methods and some basic Data Structures and Algorithms of JavaScript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LhYi4A_iq4vLBncN3fHieQ.png" /></figure><h4>1. React Behind the scene:</h4><p>Interestingly React works in a unique way behind the scene. There are some mechanisms that React follows to compile UI inside the browser. We are briefly describing them one by one:</p><blockquote><strong>JSX</strong></blockquote><p>A syntax that is not either HTML or JavaScript, but a common language for both. By using JSX we can put HTML inside JavaScript code and vice versa.</p><blockquote><strong>Babel</strong></blockquote><p>Transpiles (Translate + Compile) ES6 code into ES5 code to support the latest features of the language for most browsers. It also transpiles JSX syntax into the JavaScript code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WtSlV_6d9ihi8XQ_.png" /></figure><blockquote><strong>Webpack</strong></blockquote><p>An open-source JavaScript module bundler which bundles lots of files into a few files.</p><blockquote><strong>node</strong></blockquote><p>A runtime environment for JavaScript that allows us to run JavaScript code outside the browser.</p><blockquote><strong>npm</strong></blockquote><p>A package manager for node apps.</p><h4>2. Virtual DOM</h4><p>Virtual DOM is a React object which is the Virtual version of the actual browser DOM. React always create a virtual version of DOM whenever it detects a change in UI from the user.</p><p><strong>Remember that,</strong><br><em>Virtual DOM → React Object<br>Browser DOM (DOM) → Browser Object</em></p><p>Whenever there is a change in the app, React creates a new Virtual DOM. Virtual DOM is too fast than the actual browser DOM. It can produce 200,000 Virtual DOM <strong>nodes </strong>within one second. Every time there’s a change detected in the UI, React creates Virtual DOM from complete scratch.</p><h4>3. Why React is named to React?</h4><p><strong><em>React </em></strong>is named as React because of it’s nature to <strong><em>reacting </em></strong>to the User Interface (UI) with respect to the component change</p><p>Facebook named this JavaScript library as React because whenever the state of a component is affected, the UI presented to the user gets the instant replica of it.</p><h4>4. defaultProps</h4><p>It is a property on the component class itself, to set the default props for the class. This is used for undefined props, but not for null props.</p><p><strong>Example:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/0*aU530lGFTBbRZW9p.png" /></figure><p>If <strong><em>props.color</em></strong> is not provided, it will be set by default to <strong><em>‘blue’</em></strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/0*YVIUp2dVXGyhkqMU.png" /></figure><p>If <strong><em>props.color</em></strong> is set to null, it will remain <strong><em>null</em></strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/0*ta1e5lh-SVjzR7BU.png" /></figure><h4>5. Error Boundaries</h4><p>Error boundaries are React components that <strong>catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI</strong> instead of the component tree that crashed. Error boundaries catch errors during rendering, in lifecycle methods, and in constructors of the whole tree below them.</p><p><strong>Example:</strong></p><p>We can use it as a regular component</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/0*0RhU1U_zlcwIQJLJ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/0*OAuFzG7s0hBJN2Rl.png" /></figure><h4>6. How to effectively Unit Test React Apps</h4><p>Unit Testing<strong> </strong>is a type of software testing where individual units or components of a software are tested. The purpose is to validate that each unit of the software code performs as expected.</p><p>No matter what library or framework we use (including React), the following tips will help us to write better, more testable, more readable, more composable UI components:</p><ul><li><strong>Favor pure components for UI code:</strong> given the same props, always render the same component. If you need state from the app, you can wrap those pure components with a container component that manages state and side-effects.</li><li><strong>Isolate application logic/business rules</strong> in pure reducer functions.</li><li><strong>Isolate side effects</strong> using container components.</li></ul><h4>7. What are Hooks in React?</h4><p>React Hooks lets us use state, and other React features without having to define a JavaScript class. Hooks are simply regular JavaScript functions!</p><p><strong>Example (with hooks):</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Uc-rX2yjnNf5SJV1.png" /></figure><p><strong>Example (without hooks):</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*I3xMFiWU5YdFjf2J.png" /></figure><h4>8. Rules of using Hooks</h4><p><strong>i) Only call Hooks at the Top Level<br></strong><em>We can’t call Hooks inside loops, conditions, or nested functions.</em> Instead, we can always use Hooks at the top level of our React function. By following this rule, we ensure that Hooks are called in the same order each time a component renders.</p><p><strong>ii) Only Call Hooks from React Functions<br></strong>In spite of being a JavaScript function, we can’t call Hooks from regular JavaScript functions. Rather, we can:</p><ul><li><em>Call Hooks from React function components.</em></li><li><em>Call Hooks from custom Hooks</em></li></ul><h4>9. The useRef() Hooks behaves like instance variables</h4><p>The “ref” object of <strong><em>useRef()</em></strong> hooks is a generic container whose <strong><em>current </em></strong>property is mutable and can hold any value, which is similar to an instance property of a class. We can write to it from inside <strong><em>useEffect</em></strong></p><p><strong>Example:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/0*EL-ahjHB4o1cue4E.png" /></figure><p>If we just wanted to set an interval, we wouldn’t need the ref ( <strong><em>id </em></strong>could be local to the effect), but it’s useful if we want to clear the interval from an event handler.</p><p><strong>Example:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/0*Z8Rn0bUoWMkPB4FO.png" /></figure><h4>10. Higher-Order Components (HOC)</h4><p>Higher-order components are functions that take a component and returns a new component.<br>This is an advanced technique in React for reusing component logic.</p><p><strong>Example:</strong></p><pre><strong>const EnhancedComponent = higherOrderComponent(WrappedComponent);</strong></pre><h4>11. Web accessibility</h4><blockquote><strong>The power of the Web is in its universality.<br>Access by everyone regardless of disability is an essential aspect.</strong></blockquote><blockquote>— Tim Berners-Lee, inventor of the world wide web</blockquote><p>Web accessibility is the inclusive practice of ensuring there are no barriers that prevent interaction with, or access to, websites on the World Wide Web by people with physical disabilities, situational disabilities, and socio-economic restrictions on bandwidth and speed.</p><p>React fully supports building accessible websites, often by using standard HTML techniques.</p><h4>12. Component Lifecycle of React</h4><p>Every <strong>React Component</strong> has a <strong>lifecycle</strong> of its own, the <strong>lifecycle</strong> of a <strong>component</strong> can be defined as the series of methods that are invoked in different stages of the <strong>component’s</strong> existence.</p><p><strong><em>commonly used lifecycle methods</em></strong></p><p>i) for Mounting — <em>constructor(), render(), componentDidMount()</em></p><p>ii) for Updating — <em>render(), componentDidUpdate()</em></p><p>iii) for Unmounting — <em>componentWillUnmount()</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AQ81DtValyIGZ2hG.png" /></figure><h4>13. Queue - Data Structure</h4><p>Queues are data structures that follow the First In First Out (FIFO) i.e. the first element that is added to the queue is the first one to be removed.</p><p>Elements are always added to the back and removed from the front. Think of it as a line of people waiting for a bus. The person who is at the beginning of the line is the first one to enter the bus.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/0*S7YUz8LCNS5KuLSR.png" /></figure><p>A Queue basically has three operations:</p><ul><li>enqueue</li><li>dequeue</li><li>peek</li></ul><p>Here’s an implementation of Queue with JavaScript:</p><pre>class Queue {<br>  constructor() {<br>    // array to hold our values<br>    this.queue = [];<br>    // length of the array - could also track this with queue.length<br>    this.length = 0;<br>  }<br><br>  enqueue(value) {<br>   <br>  }<br><br>  dequeue() {<br>    <br>  }<br>  <br>  peek() {<br>    <br>  }<br>}</pre><p><strong><em>enqueue() method</em></strong></p><pre>enqueue(value) {<br><em>  // add the value to the start of the queue</em><br>  this.queue.unshift(value);<br><em>  // update our length</em><br>  this.length++;<br>}</pre><p><strong><em>dequeue() method</em></strong></p><pre>dequeue() {<br><em>  // if we have any values</em><br>  if (this.length &gt; 0) {<br><em>    // pop off the value that was added first</em><br>    this.queue.pop();<br><em>    // decrement the length</em><br>    this.length--;<br>  }<br>}</pre><p><strong><em>peek() method</em></strong></p><pre>peek() {<br>  const lastValIndex = this.length - 1;<br>  if (lastValIndex &gt;= 0) {<br>    return this.queue[lastValIndex];<br>  }<br>  return false;<br>}</pre><h4>14. Linked list - Data Structure</h4><p>A linked list is a way to store a collection of elements. Like an array, these can be character or integers. Each element in a linked list is stored in the form of a node.</p><p><strong><em>Node:<br></em></strong>A node is a collection of two sub-elements or parts. A data part that stores the element and a next part that stores the link to the next node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/0*a2tikvt67o_0cApx.png" /></figure><p><strong><em>Linked List:<br></em></strong>A linked list is formed when many such nodes are linked together to form a chain. Each node points to the next node present in the order. The first node is always used as a reference to traverse the list and is called HEAD. The last node points to NULL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/0*UcT7ouksNWljdWP4.png" /></figure><p>Linked list basically has the following operations:</p><ul><li>node</li><li>list of linked data</li><li>inserting data</li><li>removing data (from the specific index)</li><li>clearing the list</li></ul><p>Here’s an implementation of Queue with JavaScript:</p><p><strong><em>Node Class</em></strong></p><pre>class Node {<br>  constructor(data, next = null) {<br>    this.data = data;<br>    this.next = next;<br>  }<br>}</pre><p><strong><em>LinkedList Class</em></strong></p><pre>class LinkedList {<br>  constructor() {<br>    this.head = null;<br>    this.size 0;<br>  }<br>}</pre><p><strong><em>insert() method</em></strong></p><pre><em>// insert will add to the end of our linked list</em><br>insert(data) {<br>  // create a node object using the data passed in<br>  let node = new Node(data);<br>  let current;<br><em>  // if we don&#39;t have a head, we make one</em><br>  if (!this.head) {<br>    this.head = node;<br>  } else {<br><em>    // if there is already a head, then we add a node to our list</em><br>    current = this.head;<br><em>    // loop until the end of our linked list (the node with no next value)</em><br>    while (current.next) {<br>      current = current.next;<br>    }<br><em>    // set the next value to be the current node</em><br>    current.next = node;<br>  }<br><em>  // increment the size</em><br>  this.size++;<br>}</pre><p><strong><em>removeAt() method</em></strong></p><pre><em>// Remove at index</em><br>  removeAt(index) {<br><em>    // check if index is a positive number and index isn&#39;t too large</em><br>    if (index &gt; 0 &amp;&amp; index &gt; this.size) {<br>      return;<br>    }<br>    // start at our head<br>    let current = this.head;<br><em>    // keep a reference to the previous node</em><br>    let previous;<br><em>    // count variable</em><br>    let count = 0;<br><em>    // if index is 0, then point the head to the item second (index 1) in the list</em><br>    if (index === 0) {<br>      this.head = current.next;<br>    } else {<br><em>      // loop over the list and</em> <br>      while (count &lt; index) {<br><em>        // first increment the count</em><br>        count++;<br><em>        // set previous to our current node</em><br>        previous = current;<br> <em>       // now set our current node to the next node</em><br>        current = current.next;<br>      }<br><em>      // update the next pointer of our previous node to be the next node</em><br>      previous.next = current.next;<br>    }<br><em>    // since we removed a node we decrement, the size by 1</em><br>    this.size--;<br>  }</pre><p><strong><em>clearList() method</em></strong></p><pre>clearList() {<br>  this.head = null;<br>  this.size = 0;<br>}</pre><h4>15. Binary Search Tree - Data Structure</h4><p>Binary search trees sometimes called ordered or sorted binary trees, are a particular type of container: a data structure that stores “items” in memory.</p><p>A binary search tree includes the following terms:</p><ul><li><strong>Root:</strong> This is the very top node of a tree structure and does not have a parent</li><li><strong>Parent:</strong> It is a child of a node but also the parent of a node</li><li><strong>Child:</strong> This node is the child of a node and does not necessarily have a child</li></ul><p>In a binary search tree, each node either has zero, one, or two children. The child on the left is called the left child, and the child on the right is the right child. In a binary search tree, the child on the left must be smaller than the child on the right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/0*8oicW9NVTMwbJtw3.png" /></figure><p>We will use the following terms to implement a Binary Search Tree with JavaScript:</p><ul><li>Tree</li><li>Node</li><li>root</li><li>left</li><li>right</li><li>add</li><li>current</li><li>contains</li></ul><p><strong><em>Tree Class</em></strong></p><pre>class Tree {<br>   constructor(value) {<br>     this.root = null<br>   }</pre><pre>   add(value) {<br><em>    // we&#39;ll implement this below</em><br>   }</pre><pre>}</pre><p><strong><em>Node Class</em></strong></p><pre>class Node {<br>  constructor(value, left = null, right = null) {<br>    this.value = value;<br>    this.left = left;<br>    this.right = right;<br>  }<br>}</pre><p><strong><em>add() method</em></strong></p><pre>add(value) {<br><em>    // if we do not have a root, then we create one</em><br>    if (this.root === null) {<br>      this.root = new Node(value);<br>      return;<br>    }<br>    let current = this.root;<br><em>    // keep looping</em><br>    while (true) {<br><em>      // go left if our current value is greater<br>      // than the value passed in</em><br>      if (current.value &gt; value) {<br><em>        // if there is a left child, then run the<br>        // loop again</em><br>        if (current.left) {<br>          current = current.left;<br>        } else {<br>          current.left = new Node(value);<br>          return;<br>        }<br>      }<br><em>      // the value is smaller, so we go right</em><br>      else {<br><em>        // go right<br>        // if there is a left child, then run the<br>        // loop again</em><br>        if (current.right) {<br>          current = current.right;<br>        } else {<br>          current.right = new Node(value);<br>          return;<br>        }<br>      }<br>    }<br>}</pre><p>if we call the add() method,</p><blockquote>const t = new Tree();<br>t.add(2);<br>t.add(5);<br>t.add(3);</blockquote><p>we will get the following output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/0*BTPYii4L-RPaMsC6.png" /></figure><p><strong><em>contains() method</em></strong></p><pre>contains(value) {<br><em>  // get the root</em><br>  let current = this.root;<br><em>  // while we have a node</em><br>  while (current) {<br><em>    // check if our current node has the value</em><br>    if (value === current.value) {<br>      return true; <em>// leave the function</em><br>    }<br>    <em>// we decide on the next current node by comparing our value</em><br><em>    // against current.value - if its less go left else right</em><br>    current = value &lt; current.value ? current.left : current.right;<br>  }<br>  return false;<br>}</pre><h4>16. Binary Search - Algorithm</h4><p>A simple search algorithm that searches a sorted array by repeatedly dividing the search interval in half. Begin with an interval covering the whole array.</p><p>If the value of the search key is less than the item in the middle of the interval, narrow the interval to the lower half. Otherwise narrow it to the upper half. Repeatedly check until the value is found or the interval is empty.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zF2TPPbGGzgkYLRS.png" /></figure><blockquote>The idea of <strong>binary search</strong> is to use the information that the array is sorted and reduce the <strong>time complexity</strong> to <strong>O(log n)</strong>.</blockquote><p><strong>Implementing Binary Search - JavaScript</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/0*kJ-NaZsyklIt9Vju.png" /></figure><h4>17. Selection Sort - Algorithm</h4><p>Selection sort is a sorting algorithm, specifically an in-place comparison sort. It has O(n²) time complexity, making it inefficient on large lists, and generally performs worse than the similar insertion sort.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/100/0*jAfXkkX_gttu8Zpr.png" /></figure><p><strong>Time Complexity of Selection Sort:</strong></p><p><em>Best Case - O(n²)</em></p><p><em>Average - O(n²)</em></p><p><em>Worst - O(n²)</em></p><p><strong>Implementing Selection Sort - JavaScript</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/0*o3SSzyiqWKLG6Pcg.png" /></figure><h4>18. Merge Sort - Algorithm</h4><p>Merge sort is an efficient, general-purpose, comparison-based sorting algorithm. Most implementations produce a stable sort, which means that the implementation preserves the input order of equal elements in the sorted output.</p><blockquote><strong>Mergesort is a divide and conquer algorithm that was invented by John von Neumann in 1945.</strong></blockquote><p>A recursive merge sort algorithm used to sort an array of 7 integer values. These are the steps a human would take to emulate merge sort (top-down).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/0*nANvcOc0e-fBt7w_.png" /></figure><p><strong>Time Complexity of Merge Sort:</strong></p><p><em>Best - n log(n)</em></p><p><em>Average - n log(n)</em></p><p><em>Worst - n log(n)</em></p><p><strong>Implementing Merge Sort - JavaScript</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/0*ZEho7Q_KR2mkOBoE.png" /></figure><p><em>The whole article was the overall short summary of the 2nd week of JavaScript and React learning. Hence, the Milestone-2 has been completed today, the 7th day of the week since we have started the second week.</em></p><p><strong>Thanks for reading. Give a clap, if you liked the article.<br>Happy Learning :)</strong></p><p><strong><em>For more details and References:</em></strong></p><p><a href="https://medium.com/@rbiswas596/react-under-the-hood-68c8b5258b0c"><em>https://medium.com/@rbiswas596/react-under-the-hood-68c8b5258b0c</em></a></p><p><a href="https://medium.com/@rbiswas596/easy-react-e82ad4055401"><em>https://medium.com/@rbiswas596/easy-react-e82ad4055401</em></a></p><p><a href="https://medium.com/@rbiswas596/hook-up-with-the-react-hooks-7b14e2cd88a6"><em>https://medium.com/@rbiswas596/hook-up-with-the-react-hooks-7b14e2cd88a6</em></a></p><p><a href="https://medium.com/@rbiswas596/revisiting-react-f28da9afdf99"><em>https://medium.com/@rbiswas596/revisiting-react-f28da9afdf99</em></a></p><p><a href="https://medium.com/@rbiswas596/data-structures-with-javascript-a709aca5cd27"><em>https://medium.com/@rbiswas596/data-structures-with-javascript-a709aca5cd27</em></a></p><p><a href="https://medium.com/@rbiswas596/algorithms-with-javascript-75b867b74865"><em>https://medium.com/@rbiswas596/algorithms-with-javascript-75b867b74865</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2785509ac06" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Algorithms with JavaScript]]></title>
            <link>https://medium.com/analytics-vidhya/algorithms-with-javascript-75b867b74865?source=rss-8499b6585dc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/75b867b74865</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[js]]></category>
            <category><![CDATA[javascript-algorithms]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Rahul Biswas]]></dc:creator>
            <pubDate>Sat, 09 May 2020 13:32:41 GMT</pubDate>
            <atom:updated>2020-05-17T16:34:10.867Z</atom:updated>
            <content:encoded><![CDATA[<h3>A Day with JavaScript Algorithms - Milestone 2 (Day 6 - Week 2)</h3><p>Today we will briefly discuss some simple and basic but mostly used Algorithms of any programming language including JavaScript. We will be covering - Mathematical Algorithms like Factorial and Fibonacci, Searching Algorithms like Linear Search and Binary Search, Sorting Algorithms like Bubble Sort, Selection Sort, Insertion Sort, Merge Sort, Quick Sort, and Heap Sort and also their implementations. So, let’s jump into this interesting article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*j3MFhGsSE2uZeiIsG_bfgw.png" /></figure><h4>1. Factorial</h4><p>In mathematics, the factorial of a positive integer <strong><em>n</em></strong>, denoted by <strong><em>n!</em></strong>, is the product of all positive integers less than or equal to <strong><em>n</em></strong>:</p><blockquote><strong>n! = n x (n - 1) x (n - 2) x (n - 3) x … x 3 x 2 x 1</strong></blockquote><p>For example,</p><blockquote><strong>5! = 5 x 4 x 3 x 2 x 1 = 120</strong></blockquote><p>Similarly, <br><em>6! = 720, 7! = 5040, 8! = 40320, 9! = 362880, 10! = 3628800</em></p><p><em>Except</em> <strong><em>0! = 1</em></strong> <em>(according to the convention for an empty product)</em></p><p><strong>Iterative Factorial - JavaScript</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*oucKi-vhXLUyc1p56Ds2Gw.png" /></figure><p><strong>Recursive Factorial - JavaScript</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6PogAI724eh5in1GfvurZw.png" /></figure><h3>2. Fibonacci Number</h3><p>In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones:</p><blockquote><strong>0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, …</strong></blockquote><p><strong><em>I found this one interesting:<br></em></strong><em>A tiling with squares whose side lengths are successive Fibonacci numbers</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*Zo-Wh0fnTlTqHpw3JR21tg.png" /></figure><blockquote><strong>The Fibonacci spiral:</strong> an approximation of the golden spiral created by drawing circular arcs connecting the opposite corners of squares in the Fibonacci tiling;[4] this one uses squares of sizes 1, 1, 2, 3, 5, 8, 13 and 21.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*kAXN8LoWIz3oyM2v1_5a3Q.png" /></figure><p><strong>Iterative Factorial - JavaScript</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*z69GU_g0jGa0OuLuyYsLeg.png" /></figure><p><strong>Recursive Factorial - JavaScript</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*NqBfpYlrQbbaPcshTtW6Tg.png" /></figure><h3>3. Linear Search</h3><p>Linear Search or sequential search is a method for finding a target value within a list. It sequentially checks each element of the list for the target value until a match is found or until all the elements have been searched. Linear search runs in at worst linear time and makes at most n comparisons, where n is the length of the list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*m6Ni_Ry4iRIPMHY44uy49A.gif" /></figure><blockquote>The <strong>Time Complexity</strong> of Linear Search is <strong>O(n)</strong> in <strong>worst case</strong> we&#39;re checking each element exactly once.</blockquote><p><strong>Linear Search - JavaScript</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*Jocv9i8C6C8PnUql9acvHA.png" /></figure><p><strong>Why linear search is not efficient<br></strong>There is no doubt that linear search is simple. But because it compares each element one by one, it is time-consuming and therefore not very efficient. If we have to find a number from, say, 1,000,000 numbers and that number is at the last position, a linear search technique would become quite tedious.</p><p>So we should also learn about bubble sort, quick sort, and other more efficient algorithms.</p><h3>4. Binary Search</h3><p>A simple search algorithm that searches a sorted array by repeatedly dividing the search interval in half. Begin with an interval covering the whole array.</p><p>If the value of the search key is less than the item in the middle of the interval, narrow the interval to the lower half. Otherwise narrow it to the upper half. Repeatedly check until the value is found or the interval is empty.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*pLjDTIJBIPY4u0I97xvSaA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tyh5EfBnl9_Vkkc66tVCeA.png" /></figure><blockquote>The idea of <strong>binary search</strong> is to use the information that the array is sorted and reduce the <strong>time complexity</strong> to <strong>O(log n)</strong>.</blockquote><p><strong>Binary Search — JavaScript</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*x-AgLOMoF1l-tEI15kZXGQ.png" /></figure><h3>5. Bubble Sort</h3><p>Bubble sort is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order (ascending or descending arrangement). The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*1MiLjMYgr2r2fDORCJn89w.gif" /></figure><p><strong>Time Complexity of Bubble Sort:</strong></p><p><em>Best - n</em></p><p><em>Average - n²</em></p><p><em>Worst - n²</em></p><p><strong>Bubble Sort - JavaScript</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*SnzBpDBcd2CCCOVQmm_h7A.png" /></figure><h3>6. Selection Sort</h3><p>Selection sort is a sorting algorithm, specifically an in-place comparison sort. It has O(n²) time complexity, making it inefficient on large lists, and generally performs worse than the similar insertion sort.</p><p>Selection sort is noted for its simplicity, and it has performance advantages over more complicated algorithms in certain situations, particularly where auxiliary memory is limited.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/100/1*8guImFhbPKA4Q9k84sNaaA.png" /></figure><p><strong>Time Complexity of Selection Sort:</strong></p><p><em>Best - O(n²)</em></p><p><em>Average - O(n²)</em></p><p><em>Worst - O(n²)</em></p><p><strong>Selection Sort - JavaScript</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*t6BabPcKHrszxrFxceN5Yw.png" /></figure><h3>7. Insertion Sort</h3><p>Insertion sort is a simple sorting algorithm that works the way we sort playing cards in our hands. It builds the final sorted array (or list) one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*bmfRxyIQZEK0Iu5T6YV1sw.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*EZY_Nyos3QWiHvcAov-Nxw.png" /></figure><p><strong>Time Complexity of Insertion Sort:</strong></p><p><em>Best - O(n)</em></p><p><em>Average - O(n²)</em></p><p><em>Worst - O(n²)</em></p><p><strong>Selection Sort - JavaScript</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g5TAWPQK2NiG17Jwm7dTuQ.png" /></figure><h3>8. Merge Sort</h3><p>Merge sort is an efficient, general-purpose, comparison-based sorting algorithm. Most implementations produce a stable sort, which means that the implementation preserves the input order of equal elements in the sorted output.</p><blockquote><strong>Mergesort is a divide and conquer algorithm that was invented by John von Neumann in 1945.</strong></blockquote><p>An example of merge sort. First divide the list into the smallest unit (1 element), then compare each element with the adjacent list to sort and merge the two adjacent lists. Finally all the elements are sorted and merged.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*opwN0BhtH4zvPF697fPlow.gif" /></figure><p>A recursive merge sort algorithm used to sort an array of 7 integer values. These are the steps a human would take to emulate merge sort (top-down).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/838/1*4iBX5bSs3caaf9w3l4sJow.png" /></figure><p><strong>Time Complexity of Merge Sort:</strong></p><p><em>Best - n log(n)</em></p><p><em>Average - n log(n)</em></p><p><em>Worst - n log(n)</em></p><p><strong>Merge Sort - JavaScript</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/1*8Y2lts_MvwDt-VnNQVzSpg.png" /></figure><h3>9. Quicksort</h3><p>Quicksort is a divide and conquer algorithm. Quicksort first divides a large array into two smaller sub-arrays: the low elements and the high elements. Quicksort can then recursively sort the sub-arrays</p><p><strong><em>The steps are:</em></strong></p><blockquote>Pick an element, called a <strong>pivot</strong>, from the array.</blockquote><blockquote><strong>Partitioning</strong>: reorder the array so that all elements with values less than the pivot come before the pivot, while all elements with values greater than the pivot come after it (equal values can go either way). After this partitioning, the pivot is in its final position. This is called the partition operation.</blockquote><blockquote><strong>Recursively </strong>apply the above steps to the <strong>sub-array</strong> of elements with smaller values and separately to the <strong>sub-array</strong> of elements with greater values.</blockquote><p>Animated visualization of the quicksort algorithm. The horizontal lines are pivot values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*1OXQp3jbpyUJHYMX5rrJOQ.gif" /></figure><p><strong>Time Complexity of Quick Sort:</strong></p><p><em>Best - n log(n)</em></p><p><em>Average - log(n)</em></p><p><em>Worst - n²</em></p><p><strong>Quick Sort - JavaScript</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*I41hUM4BRX8o-y9cikQ4kQ.png" /></figure><h3>10. Heap Sort</h3><p>Heapsort is a comparison-based sorting algorithm. Heapsort can be thought of as an <strong><em>improved selection sort</em></strong>: like that algorithm, it divides its input into a sorted and an unsorted region, and it iteratively shrinks the unsorted region by extracting the largest element and moving that to the sorted region. The improvement consists of the use of a heap data structure rather than a linear-time search to find the maximum.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*t5B9NRgJKTxgZYsLhwU8Zg.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*LVcbTeL6zPLfDHiQ2w3Jtw.gif" /></figure><p><strong>Time Complexity of Heap Sort:</strong></p><p><em>Best - n log(n)</em></p><p><em>Average - n log(n)</em></p><p><em>Worst - n log(n)</em></p><p><strong>Heap Sort - JavaScript</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*zEhnGEBFMYPxMRZnvZmP-Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*Tgnf0rWDJiF2cG0RS546rw.png" /></figure><p><strong>That’s all for today…Thanks for Reading. Happy Learning :)</strong></p><p><strong><em>Resources Reference:</em></strong></p><p><a href="https://github.com/trekhleb/javascript-algorithms?fbclid=IwAR1_ulw28fQyQeDHxKpjXx5jlEx6UTI9MSv6pW4dLgfSDZEHbICX7GQ-zrw"><em>https://github.com/trekhleb/javascript-algorithms</em></a></p><p><a href="https://www.freecodecamp.org/news/linear-search/"><em>https://www.freecodecamp.org/news/linear-search/</em></a></p><p><a href="https://en.wikipedia.org/wiki/Binary_search_algorithm"><em>https://en.wikipedia.org/wiki/Binary_search_algorithm</em></a></p><p><a href="https://www.geeksforgeeks.org/binary-search/"><em>https://www.geeksforgeeks.org/binary-search/</em></a></p><p><a href="https://reactgo.com/binary-search-algorithm-javascript/"><em>https://reactgo.com/binary-search-algorithm-javascript/</em></a></p><p><a href="https://www.w3resource.com/javascript-exercises/searching-and-sorting-algorithm/index.php"><em>https://www.w3resource.com/javascript-exercises/searching-and-sorting-algorithm/index.php</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75b867b74865" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/algorithms-with-javascript-75b867b74865">Algorithms with JavaScript</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>