<?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 Iqbal Mahmud on Medium]]></title>
        <description><![CDATA[Stories by Iqbal Mahmud on Medium]]></description>
        <link>https://medium.com/@mahmud886?source=rss-8e6ba8805fe7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*djqj2Eved8CJb1eZ</url>
            <title>Stories by Iqbal Mahmud on Medium</title>
            <link>https://medium.com/@mahmud886?source=rss-8e6ba8805fe7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 23 May 2026 16:25:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mahmud886/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[10 BASIC INTERVIEW QUESTIONS -- FLUID DESIGN AND VUE JS]]></title>
            <link>https://medium.com/@mahmud886/10-basic-interview-questions-fluid-design-and-vue-js-7ddb2f4f02a3?source=rss-8e6ba8805fe7------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ddb2f4f02a3</guid>
            <dc:creator><![CDATA[Iqbal Mahmud]]></dc:creator>
            <pubDate>Sat, 30 May 2020 14:50:39 GMT</pubDate>
            <atom:updated>2020-05-30T14:50:39.973Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>10 BASIC INTERVIEW QUESTIONS -- FLUID DESIGN AND VUE JS</strong></p><ol><li><strong>What is Fluid Design</strong></li></ol><p><em>Fluid Design means that different sections of the site are defined relatively (eg, an element is 50% of the page width). No matter what browser you’re using: Smartphone, Tablet, Desktop, the site will look (mostly) the same and have the same proportions (this element will take up half the screen).</em></p><p>2.<strong> Difference Between Fixed And Fluid Layouts</strong></p><p><em>Although most designers and developers would consider defining fixed and fluid website layouts to be elementary, we’ll go over it just to be clear.</em></p><p><strong>FIXED WEBSITE LAYOUTS</strong></p><p><em>A fixed website layout has a wrapper that is a fixed width, and the components inside it have either percentage widths or fixed widths. The important thing is that the container (wrapper) element is set to not move. No matter what screen resolution the visitor has, he or she will see the same width as other visitors.</em></p><p><strong>FLUID WEBSITE LAYOUTS</strong></p><p><em>In a fluid website layout, also referred to as a liquid layout, the majority of the components inside have percentage widths, and thus adjust to the user’s screen resolution.</em></p><p>3.<strong> FLUID LAYOUTS</strong></p><p><em>A fluid layout is a type of webpage design in which layout of the page resizes as the window size is changed. This is accomplished by defining areas of the page using percentages instead of fixed pixel widths. Most webpage layouts include one, two, or three columns</em></p><p>4. <strong>What is Vue.js?</strong></p><p><em>Vue.js lets you extend HTML with HTML attributes called directives<br>Vue.js directives offers functionality to HTML applications<br>Vue.js provides built-in directives and user defined directives</em></p><p>5.<strong> Vue.js Directives</strong></p><p><em>Vue.js uses double braces {{ }} as place-holders for data.<br>Vue.js directives are HTML attributes with the prefix v-</em></p><p><strong>Vue Example</strong></p><p><em>In the example below, a new Vue object is created with new Vue().<br>The property el: binds the new Vue object to the HTML element with id=&quot;app&quot;.</em></p><p>6.<strong> Virtual DOM</strong></p><p><em>VueJS makes the use of virtual DOM, which is also used by other frameworks such as React, Ember, etc. The changes are not made to the DOM, instead a replica of the DOM is created which is present in the form of JavaScript data structures. Whenever any changes are to be made, they are made to the JavaScript data structures and the latter is compared with the original data structure. The final changes are then updated to the real DOM, which the user will see changing. This is good in terms of optimization, it is less expensive and the changes can be made at a faster rate</em>.</p><p>7. VueJS v/s React</p><p><strong>Virtual DOM</strong><br><em>Virtual DOM is a virtual representation of the DOM tree. With virtual DOM, a JavaScript object is created which is the same as the real DOM. Any time a change needs to be made to the DOM, a new JavaScript object is created and the changes are made. Later, both the JavaScript objects are compared and the final changes are updated in the real DOM.<br>VueJS and React both use virtual DOM, which makes it faster.<br></em><strong>Template v/s JSX</strong><em><br>VueJS uses html, js and css separately. It is very easy for a beginner to understand and adopt the VueJS style. The template based approach for VueJS is very easy.<br>React uses jsx approach. Everything is JavaScript for ReactJS. HTML and CSS are all part of JavaScript.</em></p><p>8. <strong>Data Binding</strong></p><p><em>The data binding feature helps manipulate or assign values to HTML attributes, change the style, assign classes with the help of binding directive called v-bind available with VueJS</em>.</p><p>9. <strong>Vue-CLI</strong></p><p><em>VueJS can be installed at the command line using the vue-cli command line interface. It helps to build and compile the project easily using vue-cli.</em></p><p>10. <strong>Advantage of using Vue JS<em>.</em></strong></p><p><em>advantages of using Vue. JS | the The Progressive JavaScript Framework small. The success of JavaScript framework depends on its size. ...</em></p><p><em>Easy to Understand. One of the reasons for the popularity of this framework is that it is quite easy to understand. ...</em></p><p><em>Simple Integration</em></p><p><em>Flexibility</em></p><p><em>Two-Way Communication</em></p><p><em>Great Tooling</em></p><p><em>Best of both worlds</em>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ddb2f4f02a3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[10 JavaScript Coding Interview Questions Solve With Code]]></title>
            <link>https://medium.com/swlh/10-javascript-coding-interview-questions-solve-with-code-3d0a22393a69?source=rss-8e6ba8805fe7------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d0a22393a69</guid>
            <category><![CDATA[interview-preparation]]></category>
            <category><![CDATA[javascript-interview]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[interview-questions]]></category>
            <dc:creator><![CDATA[Iqbal Mahmud]]></dc:creator>
            <pubDate>Sat, 16 May 2020 16:39:35 GMT</pubDate>
            <atom:updated>2020-06-13T20:08:43.184Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*XnAF5bhbCeD8sfY8ykMkVA.jpeg" /></figure><h3>Q-1: Write a function that would allow you to do this</h3><p><em>You can create a closure to keep the value of a even after the inner function is returned. The inner function that is being returned is created within an outer function, making it a closure, and it has access to the variables within the outer function, in this case the variable </em><em>a.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SJmx8qafewSUaYDO8wSJ3w.png" /></figure><h3>Q-2: Palindrome</h3><p><em>A palindrome is a word, sentence or other type of character sequence which reads the same backward as forward. For example, “racecar” and “Anna” are palindromes. “Table” and “John” aren’t palindromes, because they don’t read the same from left to right and from right to left.</em></p><h4>Understanding the challenge</h4><p><em>The problem can be stated along the following lines: given a string, return true if the string is a palindrome and false if it isn’t. Include spaces and punctuation in deciding if the string is a palindrome. For example:</em></p><pre>palindrome(&#39;racecar&#39;)  ===  true<br>palindrome(&#39;table&#39;)  ===  false</pre><h4>Reasoning about the challenge</h4><p><em>This challenge revolves around the idea of reversing a string. If the reversed string is the same as the original input string, then you have a palindrome and your function should return true. Conversely, if the reversed string isn’t the same as the original input string, the latter is not a palindrome and your function is expected to return false.</em></p><h4>Solution</h4><p>Here’s one way you can solve the palindrome challenge:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R6u_BA3kHCeuOrj6sX-jvA.png" /></figure><p><em>Next, reverse the input string. You can do so by turning the string into an array using the String’s .split() method, then applying the Array’s .reverse() method and finally turning the reversed array back into a string with the Array’s .join() method. I’ve chained all these methods above so the code looks cleaner.</em></p><h3>Q-3: FizzBuzz</h3><p><em>This is a super popular coding challenge — the one question I couldn’t possibly leave out. Here’s how you can state the problem.</em></p><h4>Understanding the challenge</h4><p><em>The FizzBuzz challenge goes something like this. Write a function that does the following:</em></p><ul><li><em>console logs the numbers from 1 to n, where n is the integer the function takes as its parameter</em></li><li><em>logs fizz instead of the number for multiples of 3</em></li><li><em>logs buzz instead of the number for multiples of 5</em></li><li><em>logs fizzbuzz for numbers that are multiples of both 3 and 5</em></li></ul><p><em>Example:</em></p><pre>fizzBuzz(5)</pre><p>Result:</p><pre>// 1<br>// 2<br>// fizz<br>// 4<br>// buzz</pre><h4>Reasoning about the challenge</h4><p><em>One important point about FizzBuzz relates to how you can find multiples of a number in JavaScript. You do this using the modulo or remainder operator, which looks like this: </em><em>%. This operator returns the remainder after a division between two numbers. A remainder of 0 indicates that the first number is a multiple of the second number:</em></p><pre>12 % 5 // 2 -&gt; 12 is not a multiple of 5<br>12 % 3 // 0 -&gt; 12 is multiple of 3</pre><p><em>If you divide 12 by 5, the result is 2 with a remainder of 2. If you divide 12 by 3, the result is 4 with a remainder of 0. In the first example, 12 is not a multiple of 5, while in the second example, 12 is a multiple of 3.</em></p><p><em>With this information, cracking FizzBuzz is a matter of using the appropriate conditional logic that will lead to printing the expected output.</em></p><h4>Solution</h4><p><em>Here’s one solution you can try out for the FizzBuzz challenge:</em></p><p>1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WKQZnQjPACpz0XEprojtvQ.png" /></figure><p>2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bVsh2YfEBEL7GEjaqQsPKg.png" /></figure><h3>Q-1: Write a “mul” function which will properly when invoked as below syntax.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q4bRsbmsZIcuf_HFlTCIOg.png" /></figure><p><em>Here </em><em>mul function accept the first argument and return anonymous function which take the second parameter and return anonymous function which take the third parameter and return multiplication of arguments which is being passed in successive</em></p><p><em>In JavaScript function defined inside has access to outer function variable and function is the first class object so it can be returned by function as well and passed as argument in another function.</em></p><ul><li><em>A function is an instance of the Object type</em></li><li><em>A function can have properties and has a link back to its constructor method</em></li><li><em>Function can be stored as variable</em></li><li><em>Function can be pass as a parameter to another function</em></li><li><em>Function can be returned from function</em></li></ul><h3>Q-5: Implement enqueue and dequeue using only two stacks</h3><p><em>Enqueue means to add an element, dequeue to remove an element.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bOdz0K13whXpM6UGb12kQw.png" /></figure><h3>Q-6: Given a string, reverse each word in the sentence</h3><p><em>For example </em><em>Welcome to this Javascript Guide! should be become </em><em>emocleW ot siht tpircsavaJ !ediuG</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cfjFSuKd-HwdMRhwv2_i7A.png" /></figure><h3>Q-7: How to empty an array in JavaScript?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C1_Q1uY626ePsAVc9osBRw.png" /></figure><p><em>How could we empty the array above?</em></p><p><strong><em>Method 1</em></strong></p><p><em>Above code will set the variable </em><em>arrayList to a new empty array. This is recommended if you don&#39;t have </em><strong><em>references to the original array</em></strong><em> </em><em>arrayList anywhere else because It will actually create a new empty array. You should be careful with this way of empty the array, because if you have referenced this array from another variable, then the original reference array will remain unchanged, Only use this way if you have only referenced the array by its original variable </em><em>arrayList.</em></p><p><strong><em>Method 2</em></strong></p><p><em>Above code will clear the existing array by setting its length to 0. This way of empty the array also update all the reference variable which pointing to the original array. This way of empty the array is useful when you want to update all the another reference variable which pointing to </em><em>arrayList.</em></p><p><strong><em>Method 3</em></strong></p><p><em>Above implementation will also work perfectly. This way of empty the array will also update all the references of the original array.</em></p><p><strong><em>Method 4</em></strong></p><p><em>Above implementation can also empty the array. But not recommended to use often.</em></p><h3>Q-8: How would you use a closure to create a private counter?</h3><p><em>You can create a function within an outer function (a closure) that allows you to update a private variable but the variable wouldn’t be accessible from outside the function without the use of a helper function.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2fhgffBm9Pd0jDIzIIaooQ.png" /></figure><h3>Q-9: Write a function that would allow you to do this.</h3><p><em>You can create a closure to keep the value passed to the function </em><em>createBase even after the inner function is returned. The inner function that is being returned is created within an outer function, making it a closure, and it has access to the variables within the outer function, in this case the variable </em><em>baseNumber.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DzGiUu2ETaeA_KZ35aQtBA.png" /></figure><h3>Q-10: Explain what a callback function is and provide a simple example.</h3><p><em>A </em><em>callback 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 after some operations have been completed.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LKn5OCRh_DG6tfHN_X65kA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d0a22393a69" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/10-javascript-coding-interview-questions-solve-with-code-3d0a22393a69">10 JavaScript Coding Interview Questions Solve With Code</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[10 Days of JavaScript HackerRank Problem Solve]]></title>
            <link>https://medium.com/@mahmud886/10-days-of-javascript-hackerrank-problem-solve-d5520b858c9d?source=rss-8e6ba8805fe7------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5520b858c9d</guid>
            <dc:creator><![CDATA[Iqbal Mahmud]]></dc:creator>
            <pubDate>Fri, 15 May 2020 17:59:29 GMT</pubDate>
            <atom:updated>2020-05-15T17:59:29.740Z</atom:updated>
            <content:encoded><![CDATA[<h3>Day 0: Data Types</h3><p><strong>Problem</strong></p><ul><li>Function receives an integer, a float, and a string</li><li>The function has a constant integer of <strong>4</strong></li><li>The function has a constant float of <strong>4.0</strong></li><li>The function has a constant string of <strong>“HackerRank”</strong></li><li>Console log the sum of the constant integer and the integer received</li><li>Console log the sum of the constant float by the float received</li><li>Console lot the constant string following the string received on one line</li></ul><p><strong>Solution</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T_d-GyFEy92tE8yRqcnr3g.png" /></figure><h3>Day 1: Arithmetic Operators</h3><p><strong>Problem</strong></p><ul><li>A <strong><em>length</em></strong> and <strong><em>width</em></strong> are sent to two different functions</li><li><strong><em>getArea</em></strong> must return the area of the shape dimensions sent</li><li><strong><em>getPerimeter</em></strong> must return the perimeter of the shape dimensions sent</li><li>Complete the functions</li></ul><p><strong>Solution</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zDzUXtQDJECHld8pXH1v-Q.png" /></figure><p><strong>Solution 2: Optimized</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M9BHmoy1R6m9aJi6A2zNfA.png" /></figure><h3>Day 1: Functions</h3><p><strong>Problem</strong></p><ul><li>A integer of value <strong><em>n</em></strong> is provided</li><li>1 ≤ <strong><em>n</em></strong> ≤ 10</li><li>Output the factorial value of <strong><em>n</em></strong> (n!, 4! = 4 x 3 x 2 x 1 = 24)</li></ul><p><strong>Solution</strong></p><p>This can be written is a few different ways, but let’s solve it with a for loop by decreasing the value until it reaches 1;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mIH_fIbV7GPC6MzcITQQwA.png" /></figure><h3>Day 1: Let and Const</h3><p><strong>Problem</strong></p><ul><li>A float value <strong><em>r</em></strong> is provided for the radius</li><li>0 &lt; <strong><em>r</em></strong> ≤ 100</li><li>Print (console.log) the area of the circle (π x r²)</li><li>Print (console.log) the perimeter of the circle (2πr)</li><li>Do not overwrite the <strong><em>try</em></strong> and <strong><em>catch</em></strong> but make sure the code still works</li></ul><p><strong>Solution</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AWo71oLahIxN4TTGf3bBpQ.png" /></figure><h3>Day 2: Conditional Statements: If-Else</h3><p><strong>Problem</strong></p><ul><li>An integer value <strong><em>score</em></strong> is provided for a students test</li><li>0 ≤ <strong><em>score</em></strong> ≤ 30</li><li>Given the following legend, return the respective grade</li></ul><pre>If 25 &lt; score &lt;= 30, then grade = A.<br>If 20 &lt; score &lt;= 25, then grade = B.<br>If 15 &lt; score &lt;= 20, then grade = C.<br>If 10 &lt; score &lt;= 15, then grade = D.<br>If 5 &lt; score &lt;= 10, then grade = E.<br>If 0 &lt;= score &lt;= 5, then grade = F.</pre><p><strong>Solution</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EYKn_e6JO435FNzkuOVFow.png" /></figure><h3>Day 2: Conditional Statements: Switch</h3><p><strong>Problem</strong></p><ul><li>A string is provided where its length is 1 ≤ <strong><em>s</em></strong> ≤ 100</li><li>Given the following legend, return the correct value based on the first letter</li></ul><pre>First letter is a, e, i, o, or u = A.<br>First letter is b, c, d, f, or g = B.<br>First letter is h, j, k, l, or m = C.<br>First letter is n, p, q, r, s, t, v, w, x, y, z = D.</pre><p><strong>Solution</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lw9AI_1AxV2L9FZFPYPc8w.png" /></figure><h3>Day 2: Loops</h3><p><strong>Problem</strong></p><ul><li>Given a string of <strong><em>s</em></strong> of any length</li><li>Output, in order, the vowels of that string on each new line</li><li>Right after, output, in order, the consonants of that string on each new line</li></ul><pre>// Example<br>javascriptloops// Output<br>a<br>a<br>i<br>o<br>o<br>j<br>v<br>s<br>c<br>r<br>p<br>t<br>l<br>p<br>s</pre><p><strong>Solution</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0RZrul66kgUoAnZOIwF8dw.png" /></figure><h3>Day 3: Arrays</h3><p><strong>Problem</strong></p><ul><li>Receive <strong><em>n </em></strong>length array between 1 ≤ <strong><em>n</em></strong> ≤ 10</li><li>0 ≤ <strong><em>nums</em></strong> ≤ 100 as integers</li><li>Return the second largest integer of the array</li></ul><p><strong>Solution</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rm_iGOYNqpVBCSQdOHf5QQ.png" /></figure><h3>Day 3: Throw</h3><p><strong>Problem</strong></p><ul><li><strong><em>n</em></strong> number of values of <strong><em>a</em></strong> sent</li><li>1 ≤ <strong><em>n</em></strong> ≤ 5</li><li><strong><em>a</em></strong> number between -100 and 100</li><li><strong><em>a</em></strong> = 0, throw error “Zero Error”</li><li><strong><em>a</em></strong> &lt; 0, throw error “Negative Error”</li><li><strong><em>a</em></strong> &gt; 0, console log “YES”</li></ul><p><strong>Solution</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K77RJz7lf0CYxLY8oTyEvQ.png" /></figure><h3>Day 3: Try, Catch, and Finally</h3><p><strong>Problem</strong></p><ul><li>Expect a value of <strong><em>s</em></strong> of any type</li><li>If it’s a string take it return the reverse</li><li>If it’s not a string console log <em>“s.split is not a function”</em></li><li>Console.log the result of reversing or not reversing <strong>s</strong></li></ul><p><strong>Solution</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PGLkmyWijWA6M75u5G6WJQ.png" /></figure><h3>Day 4: Create a Rectangle Object</h3><p><strong>Problem</strong></p><ul><li><strong><em>a</em></strong> = length of rectangle</li><li><strong><em>b</em></strong> = width of rectangle</li><li>Complete <strong><em>Rectangle</em></strong> function to be instantiated</li><li>when <strong><em>length</em></strong> called return <strong><em>a</em></strong></li><li>when <strong><em>width</em></strong> called return <strong><em>b</em></strong></li><li>when <strong><em>perimeter</em></strong> called, return the result</li><li>when <strong><em>area</em></strong> called, return the result</li></ul><p><strong>Solution</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LUAmefw2SYtiWsLFHNfBpQ.png" /></figure><h3>Day 4: Count Objects</h3><p><strong>Problem</strong></p><ul><li><strong><em>n</em></strong> is the number of values given for <strong><em>x</em></strong> and <strong><em>y</em></strong></li><li>5 ≤ n ≤ 10</li><li><strong><em>x</em></strong> equal a coordinate between 1 and 100</li><li><strong><em>y</em></strong> equal a coordinate between 1 and 100</li><li>Return the <strong><em>index</em></strong> where the two coordinates are the same.</li></ul><p><strong>Solution</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YT_8d9GC57-7UxjwO1YmYw.png" /></figure><h3>Day 4: Classes</h3><p><strong>Problem</strong></p><ul><li>A class called <strong><em>Polygon</em></strong> is initialized with an array with share sizes</li><li>Create a JavaScript class that returns the <strong><em>perimeter</em></strong> of the shape, when <strong><em>.perimeter()</em></strong> is called</li></ul><p><strong>Solution</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZwT9RXxRcs_V8tJQkB8RlQ.png" /></figure><h3>Day 5: Inheritance</h3><p><strong>Problem</strong></p><ul><li>Create a class called <strong><em>Square</em></strong> that extends an existing class of <strong><em>Rectangle</em></strong></li><li>Add functionality to <strong><em>Rectangle</em></strong> to return the shapes <strong><em>area</em></strong></li></ul><p><strong>Solution</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dqLqbWoFAmQh4iDrituLng.png" /></figure><h3>Day 5: Template Literals</h3><p><strong>Problem</strong></p><ul><li>A function will receive literals and remaning expressions</li><li>Convert the expressing into values a and p</li><li>Return an array</li><li>Index 1= ((perimeter — Math.sqrt((Math.pow(p, 2) — (16 * area)))) / 4)<br>Index 0= ((perimeter + Math.sqrt((Math.pow(p, 2) — (16 * area)))) / 4)</li></ul><p><strong>Solution</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_76P8NH3UnliQvVWEsC-2Q.png" /></figure><h3>Day 5: Arrow Functions</h3><p><strong>Problem</strong></p><ul><li>an array of <strong><em>n</em></strong> length between 1 and 10 is received</li><li><strong><em>nums</em></strong> is the array with values between 1 and 100</li><li>if a value of <strong><em>nums</em></strong> is even multiply it by 2</li><li>if a value of <strong><em>nums</em></strong> is odd multiply it by 3</li><li>return the modified array</li></ul><p><strong>Solution</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xeyj7CR31ToZ21zZ8UFljA.png" /></figure><h3>Day 6: Bitwise Operators</h3><p><strong>Problem</strong></p><ul><li>Given an integer of <strong><em>n </em></strong>between 2 and 1000</li><li>Given an integer of <strong><em>k </em></strong>between 2 and <strong><em>n</em></strong></li><li><strong><em>q</em></strong> is just the number of lines we read from the input</li><li><strong>n</strong> is the max number of sequential numbers as a non-repeating pattern that can exist</li></ul><pre>// Example<br>n = 5// a b<br>// 1 2<br>// 1 3<br>// 1 4<br>// 1 5<br>// 2 3<br>// 2 4<br>// 2 5<br>// 3 4<br>// 3 5<br>// 4 5</pre><p><strong>Solution</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hWcBoC13HZyYxaQkRFQYbw.png" /></figure><h3>Day 6: JavaScript Dates</h3><p><strong>Problem</strong></p><ul><li>Receive a string value of <strong><em>dateString</em></strong></li><li>The format is in <strong><em>DD/MM/YYYY</em></strong> (10/11/2009)</li><li>Return the name of the day (Sunday, Monday, Tuesday,…) based on the date</li></ul><p><strong>Solution</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S4Y7_vZBxTkzDrhuM2bbrQ.png" /></figure><h3>Day 7: Regular Expressions I</h3><p><strong>Problem</strong></p><ul><li>Receive a string of <strong><em>s</em></strong> which is greater than or equal to the length of 3</li><li>Write a regular expression that validates the string</li><li>The string must be in all lowercase with characters from a-z</li><li>The string must start and end with a vowel</li><li>Return a boolean of <strong><em>true</em></strong> or <strong><em>false</em></strong> if the string meets the requirements</li></ul><p><strong>Solution</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qbsXW1lGu-TvUBsAPEiPjw.png" /></figure><h3>Day 7: Regular Expressions II</h3><p><strong>Problem</strong></p><ul><li>Receive a string of <strong><em>s</em></strong> which is greater than or equal to the length of 3</li><li>Write a regular expression that validates the string</li><li>String starts with either (Mr., Mrs., Ms., Dr., or Er.)</li><li>String doesn’t contain any spaces</li><li>String contains on the letters a-z or A-Z</li><li>Return a boolean of true or false if the string meets the requirements</li></ul><p><strong>Solution</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7TGoZ3-didnchH7zEoVUag.png" /></figure><h3>Day 7: Regular Expressions III</h3><p><strong>Problem</strong></p><ul><li>Receive a string of <strong><em>s</em></strong></li><li>length of <strong><em>s</em></strong> ≥ 3</li><li><strong><em>s</em></strong> is a string that contains numbers and letters</li><li>Write a regular expression that validates the string</li><li>The expression must only output integer numbers</li></ul><pre>// Example 1<br>// 102, 1948948 and 1.3 and 4.5<br>102<br>1948948<br>1<br>3<br>4<br>5// Example 2<br>// 1 2 3<br>1<br>2<br>3</pre><p><strong>Solution</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*foOQBpNmC3f6tra4TCNJAw.png" /></figure><h3>Day 8: Create A Button</h3><p><strong>Problem</strong></p><ul><li>Given<strong><em> index.html</em></strong>, <strong><em>js/button.js</em></strong>, and <strong><em>css/button.css</em></strong></li><li>Create an html button with an id of <strong><em>btn</em></strong></li><li><strong><em>btn</em></strong> must have the styling of: width 96px, height 48px, font-size 24px</li><li>The default innerHTML of button is set to 0</li><li>Create the interaction where when the button is clicked its internal value displayed is incremented</li></ul><pre>// Example<br>btn = 0// clicked 5 times<br>btn = 5</pre><p><strong>Solution</strong></p><p>index.html</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VyvMCEa-g3PsY0Zw7ffdfg.png" /></figure><p>button.css</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_gMmVd94F_QRWBRzszCSWQ.png" /></figure><p>button.js</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4iUBvFdXwCrFzxZaipsu0g.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5520b858c9d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[REACT INTERVIEW QUESTIONS.]]></title>
            <link>https://medium.com/@mahmud886/react-interview-questions-9ecc07d3a5ec?source=rss-8e6ba8805fe7------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ecc07d3a5ec</guid>
            <category><![CDATA[react-interview]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[interview-questions]]></category>
            <dc:creator><![CDATA[Iqbal Mahmud]]></dc:creator>
            <pubDate>Thu, 14 May 2020 16:12:15 GMT</pubDate>
            <atom:updated>2020-05-14T16:12:15.990Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Lrr7nz3jiEnc0CjwFD0bgg.png" /></figure><h3>Q-1: What is the difference between HTML and React event handling?</h3><p><em>In HTML, the event name should be in lowercase:</em></p><pre><em>&lt;button onclick=&#39;activateLasers()&#39;&gt;</em></pre><p><em>Whereas in React it follows camelCase convention:</em></p><pre><em>&lt;button onClick={activateLasers}&gt;</em></pre><p><em>In HTML, you can return </em><em>false to prevent default behavior:</em></p><pre><em>&lt;a href=&#39;#&#39; onclick=&#39;console.log(&quot;The link was clicked.&quot;); return false;&#39; /&gt;</em></pre><p><em>Whereas in React you must call </em><em>preventDefault() explicitly:</em></p><pre><em>function handleClick(event) {<br>  event.preventDefault()<br>  console.log(&#39;The link was clicked.&#39;)<br>}</em></pre><p><em>In HTML, you need to invoke the function by appending </em><em>() Whereas in react you should not append </em><em>() with the function name. (refer &quot;activateLasers&quot; function in the first point for example)</em></p><h3>Q-2: How to bind methods or event handlers in JSX callbacks?</h3><p><em>There are 3 possible ways to achieve this:</em></p><p><em>Binding in Constructor: In JavaScript classes, the methods are not bound by default. The same thing applies for React event handlers defined as class methods. Normally we bind them in constructor.</em></p><pre><em>class Component extends React.Componenet {<br>  constructor(props) {<br>    super(props)<br>    this.handleClick = this.handleClick.bind(this)<br>  }</em></pre><pre><em>  handleClick() {<br>    // ...<br>  }<br>}</em></pre><p><em>Public class fields syntax: If you don’t like to use bind approach then public class fields syntax can be used to correctly bind callbacks.</em></p><pre><em>handleClick = () =&gt; {<br>  console.log(&#39;this is:&#39;, this)<br>}</em></pre><pre><em>&lt;button onClick={this.handleClick}&gt;<br>  {&#39;Click me&#39;}<br>&lt;/button&gt;</em></pre><p><em>Arrow functions in callbacks: You can use arrow functions directly in the callbacks.</em></p><pre><em>&lt;button onClick={(event) =&gt; this.handleClick(event)}&gt;<br>  {&#39;Click me&#39;}<br>&lt;/button&gt;</em></pre><p><em>Note: If the callback is passed as prop to child components, those components might do an extra re-rendering. In those cases, it is preferred to go with </em><em>.bind() or public class fields syntax approach considering performance.</em></p><h3>Q-3: What are synthetic events in React?</h3><p><em>SyntheticEvent is a cross-browser wrapper around the browser&#39;s native event. It&#39;s API is same as the browser&#39;s native event, including </em><em>stopPropagation() and </em><em>preventDefault(), except the events work identically across all browsers.</em></p><h3>Q-4: What are “key” props and what is the benefit of using them in arrays of elements?</h3><p><em>A </em><em>key is a special string attribute you should include when creating arrays of elements. Keys help React identify which items have changed, are added, or are removed.</em></p><p><em>Most often we use IDs from our data as keys:</em></p><pre><em>const todoItems = todos.map((todo) =&gt;<br>  &lt;li key={todo.id}&gt;<br>    {todo.text}<br>  &lt;/li&gt;<br>)</em></pre><p><em>When you don’t have stable IDs for rendered items, you may use the item index as a key as a last resort:</em></p><pre><em>const todoItems = todos.map((todo, index) =&gt;<br>  &lt;li key={index}&gt;<br>    {todo.text}<br>  &lt;/li&gt;<br>)</em></pre><p><em>Note:</em></p><ol><li><em>Using indexes for keys is not recommended if the order of items may change. This can negatively impact performance and may cause issues with component state.</em></li><li><em>If you extract list item as separate component then apply keys on list component instead of </em><em>li tag.</em></li><li><em>There will be a warning message in the console if the </em><em>key prop is not present on list items.</em></li></ol><h3>Q-5: Which is preferred option with in callback refs and findDOMNode()?</h3><p><em>It is preferred to use callback refs over </em><em>findDOMNode() API. Because </em><em>findDOMNode() prevents certain improvements in React in the future.</em></p><p><em>The legacy approach of using </em><em>findDOMNode:</em></p><pre><em>class MyComponent extends Component {<br>  componentDidMount() {<br>    findDOMNode(this).scrollIntoView()<br>  }</em></pre><pre><em>  render() {<br>    return &lt;div /&gt;<br>  }<br>}</em></pre><p><em>The recommended approach is:</em></p><pre><em>class MyComponent extends Component {<br>  constructor(props){<br>    super(props);<br>    this.node = createRef();<br>  }<br>  componentDidMount() {<br>    this.node.current.scrollIntoView();<br>  }</em></pre><pre><em>  render() {<br>    return &lt;div ref={this.node} /&gt;<br>  }<br>}</em></pre><h3>Q-6: What are uncontrolled components?</h3><p><em>The Uncontrolled Components are the ones that store their own state internally, and you query the DOM using a ref to find its current value when you need it. This is a bit more like traditional HTML.</em></p><p><em>In the below UserProfile component, the </em><em>name input is accessed using ref.</em></p><pre><em>class UserProfile extends React.Component {<br>  constructor(props) {<br>    super(props)<br>    this.handleSubmit = this.handleSubmit.bind(this)<br>    this.input = React.createRef()<br>  }</em></pre><pre><em>  handleSubmit(event) {<br>    alert(&#39;A name was submitted: &#39; + this.input.current.value)<br>    event.preventDefault()<br>  }</em></pre><pre><em>  render() {<br>    return (<br>      &lt;form onSubmit={this.handleSubmit}&gt;<br>        &lt;label&gt;<br>          {&#39;Name:&#39;}<br>          &lt;input type=&quot;text&quot; ref={this.input} /&gt;<br>        &lt;/label&gt;<br>        &lt;input type=&quot;submit&quot; value=&quot;Submit&quot; /&gt;<br>      &lt;/form&gt;<br>    );<br>  }<br>}</em></pre><p><em>In most cases, it’s recommend to use controlled components to implement forms.</em></p><h3>Q-7: What are the lifecycle methods of React?</h3><p><em>React 16.3+</em></p><ul><li><em>getDerivedStateFromProps: Invoked right before calling </em><em>render() and is invoked on every render. This exists for rare use cases where you need derived state. Worth reading if you need derived state.</em></li><li><em>componentDidMount: Executed after first rendering and here all AJAX requests, DOM or state updates, and set up event listeners should occur.</em></li><li><em>shouldComponentUpdate: Determines if the component will be updated or not. By default it returns </em><em>true. If you are sure that the component doesn&#39;t need to render after state or props are updated, you can return false value. It is a great place to improve performance as it allows you to prevent a re-render if component receives new prop.</em></li><li><em>getSnapshotBeforeUpdate: Executed right before rendered output is committed to the DOM. Any value returned by this will be passed into </em><em>componentDidUpdate(). This is useful to capture information from the DOM i.e. scroll position.</em></li><li><em>componentDidUpdate: Mostly it is used to update the DOM in response to prop or state changes. This will not fire if </em><em>shouldComponentUpdate() returns </em><em>false.</em></li><li><em>componentWillUnmount It will be used to cancel any outgoing network requests, or remove all event listeners associated with the component.</em></li></ul><p><em>Before 16.3</em></p><ul><li><em>componentWillMount: Executed before rendering and is used for App level configuration in your root component.</em></li><li><em>componentDidMount: Executed after first rendering and here all AJAX requests, DOM or state updates, and set up event listeners should occur.</em></li><li><em>componentWillReceiveProps: Executed when particular prop updates to trigger state transitions.</em></li><li><em>shouldComponentUpdate: Determines if the component will be updated or not. By default it returns </em><em>true. If you are sure that the component doesn&#39;t need to render after state or props are updated, you can return false value. It is a great place to improve performance as it allows you to prevent a re-render if component receives new prop.</em></li><li><em>componentWillUpdate: Executed before re-rendering the component when there are props &amp; state changes confirmed by </em><em>shouldComponentUpdate() which returns true.</em></li><li><em>componentDidUpdate: Mostly it is used to update the DOM in response to prop or state changes.</em></li><li><em>componentWillUnmount: It will be used to cancel any outgoing network requests, or remove all event listeners associated with the component.</em></li></ul><h3>Q-8: What is the purpose of using super constructor with props argument?</h3><p><em>A child class constructor cannot make use of </em><em>this reference until </em><em>super() method has been called. The same applies for ES6 sub-classes as well. The main reason of passing props parameter to </em><em>super() call is to access </em><em>this.props in your child constructors.</em></p><p><em>Passing props:</em></p><pre><em>class MyComponent extends React.Component {<br>  constructor(props) {<br>    super(props)</em></pre><pre><em>    console.log(this.props) // prints { name: &#39;John&#39;, age: 42 }<br>  }<br>}</em></pre><p><em>Not passing props:</em></p><pre><em>class MyComponent extends React.Component {<br>  constructor(props) {<br>    super()</em></pre><pre><em>    console.log(this.props) // prints undefined</em></pre><pre><em>    // but props parameter is still available<br>    console.log(props) // prints { name: &#39;John&#39;, age: 42 }<br>  }</em></pre><pre><em>  render() {<br>    // no difference outside constructor<br>    console.log(this.props) // prints { name: &#39;John&#39;, age: 42 }<br>  }<br>}</em></pre><p><em>The above code snippets reveals that </em><em>this.props is different only within the constructor. It would be the same outside the constructor.</em></p><h3>Q-9: What are error boundaries in React v16?</h3><p><em>Error boundaries are components that catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI instead of the component tree that crashed.</em></p><p><em>A class component becomes an error boundary if it defines a new lifecycle method called </em><em>componentDidCatch(error, info) or </em><em>static getDerivedStateFromError() :</em></p><pre><em>class ErrorBoundary extends React.Component {<br>  constructor(props) {<br>    super(props)<br>    this.state = { hasError: false }<br>  }</em></pre><pre><em>  componentDidCatch(error, info) {<br>    // You can also log the error to an error reporting service<br>    logErrorToMyService(error, info)<br>  }</em></pre><pre><em>  static getDerivedStateFromError(error) {<br>     // Update state so the next render will show the fallback UI.<br>     return { hasError: true };<br>   }</em></pre><pre><em>  render() {<br>    if (this.state.hasError) {<br>      // You can render any custom fallback UI<br>      return &lt;h1&gt;{&#39;Something went wrong.&#39;}&lt;/h1&gt;<br>    }<br>    return this.props.children<br>  }<br>}</em></pre><p><em>After that use it as a regular component:</em></p><pre><em>&lt;ErrorBoundary&gt;<br>  &lt;MyWidget /&gt;<br>&lt;/ErrorBoundary&gt;</em></pre><h3>Q-10: What is ReactDOMServer?</h3><p><em>The </em><em>ReactDOMServer object enables you to render components to static markup (typically used on node server). This object is mainly used for server-side rendering (SSR). The following methods can be used in both the server and browser environments:</em></p><ol><li><em>renderToString()</em></li><li><em>renderToStaticMarkup()</em></li></ol><p><em>For example, you generally run a Node-based web server like Express, Hapi, or Koa, and you call </em><em>renderToString to render your root component to a string, which you then send as response.</em></p><pre><em>// using Express<br>import { renderToString } from &#39;react-dom/server&#39;<br>import MyPage from &#39;./MyPage&#39;</em></pre><pre><em>app.get(&#39;/&#39;, (req, res) =&gt; {<br>  res.write(&#39;&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;My Page&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&#39;)<br>  res.write(&#39;&lt;div id=&quot;content&quot;&gt;&#39;)<br>  res.write(renderToString(&lt;MyPage/&gt;))<br>  res.write(&#39;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;&#39;)<br>  res.end()<br>})</em></pre><h3>Q-11: What is CRA and its benefits?</h3><p><em>The </em><em>create-react-app CLI tool allows you to quickly create &amp; run React applications with no configuration step.</em></p><p><em>Let’s create Todo App using CRA:</em></p><pre><em># Installation<br>$ npm install -g create-react-app</em></pre><pre><em># Create new project<br>$ create-react-app todo-app<br>$ cd todo-app</em></pre><pre><em># Build, test and run<br>$ npm run build<br>$ npm run test<br>$ npm start</em></pre><p><em>It includes everything we need to build a React app:</em></p><ol><li><em>React, JSX, ES6, and Flow syntax support.</em></li><li><em>Language extras beyond ES6 like the object spread operator.</em></li><li><em>Autoprefixed CSS, so you don’t need -webkit- or other prefixes.</em></li><li><em>A fast interactive unit test runner with built-in support for coverage reporting.</em></li><li><em>A live development server that warns about common mistakes.</em></li><li><em>A build script to bundle JS, CSS, and images for production, with hashes and sourcemaps.</em></li></ol><h3>Q-12: How to re-render the view when the browser is resized?</h3><p><em>You can listen to the </em><em>resize event in </em><em>componentDidMount() and then update the dimensions (</em><em>width and </em><em>height). You should remove the listener in </em><em>componentWillUnmount() method.</em></p><pre><em>class WindowDimensions extends React.Component {<br>  constructor(props){<br>    super(props);<br>    this.updateDimensions = this.updateDimensions.bind(this);<br>  }<br>   <br>  componentWillMount() {<br>    this.updateDimensions()<br>  }</em></pre><pre><em>  componentDidMount() {<br>    window.addEventListener(&#39;resize&#39;, this.updateDimensions)<br>  }</em></pre><pre><em>  componentWillUnmount() {<br>    window.removeEventListener(&#39;resize&#39;, this.updateDimensions)<br>  }</em></pre><pre><em>  updateDimensions() {<br>    this.setState({width: window.innerWidth, height: window.innerHeight})<br>  }</em></pre><pre><em>  render() {<br>    return &lt;span&gt;{this.state.width} x {this.state.height}&lt;/span&gt;<br>  }<br>}</em></pre><h3>Q-13: Is it possible to use React without rendering HTML?</h3><p><em>It is possible with latest version (&gt;=16.2). Below are the possible options:</em></p><pre><em>render() {<br>  return false<br>}</em></pre><pre><em>render() {<br>  return null<br>}</em></pre><pre><em>render() {<br>  return []<br>}</em></pre><pre><em>render() {<br>  return &lt;React.Fragment&gt;&lt;/React.Fragment&gt;<br>}</em></pre><pre><em>render() {<br>  return &lt;&gt;&lt;/&gt;<br>}</em></pre><p><em>Returning </em><em>undefined won&#39;t work.</em></p><h3>Q-13: Why function is preferred over object for setState()?</h3><p><em>React may batch multiple </em><em>setState() calls into a single update for performance. Because </em><em>this.props and </em><em>this.state may be updated asynchronously, you should not rely on their values for calculating the next state.</em></p><p><em>This counter example will fail to update as expected:</em></p><pre><em>// Wrong<br>this.setState({<br>  counter: this.state.counter + this.props.increment,<br>})</em></pre><p><em>The preferred approach is to call </em><em>setState() with function rather than object. That function will receive the previous state as the first argument, and the props at the time the update is applied as the second argument.</em></p><pre><em>// Correct<br>this.setState((prevState, props) =&gt; ({<br>  counter: prevState.counter + props.increment<br>}))</em></pre><h3>Q-14: How to add Google Analytics for React Router?</h3><p>Add a listener on the history object to record each page view:</p><pre>history.listen(function (location) {<br>  window.ga(&#39;set&#39;, &#39;page&#39;, location.pathname + location.search)<br>  window.ga(&#39;send&#39;, &#39;pageview&#39;, location.pathname + location.search)<br>})</pre><h3>Q-15: What is the benefit of styles modules?</h3><p>It is recommended to avoid hard coding style values in components. Any values that are likely to be used across different UI components should be extracted into their own modules.</p><p>For example, these styles could be extracted into a separate component:</p><pre>export const colors = {<br>  white,<br>  black,<br>  blue<br>}</pre><pre>export const space = [<br>  0,<br>  8,<br>  16,<br>  32,<br>  64<br>]</pre><p>And then imported individually in other components:</p><pre>import { space, colors } from &#39;./styles&#39;</pre><h3>Q-16: How to make AJAX call and in which component lifecycle methods should I make an AJAX call?</h3><p><em>You can use AJAX libraries such as Axios, jQuery AJAX, and the browser built-in </em><em>fetch. You should fetch data in the </em><em>componentDidMount() lifecycle method. This is so you can use </em><em>setState() to update your component when the data is retrieved.</em></p><p><em>For example, the employees list fetched from API and set local state:</em></p><pre><em>class MyComponent extends React.Component {<br>  constructor(props) {<br>    super(props)<br>    this.state = {<br>      employees: [],<br>      error: null<br>    }<br>  }</em></pre><pre><em>  componentDidMount() {<br>    fetch(&#39;https://api.example.com/items&#39;)<br>      .then(res =&gt; res.json())<br>      .then(<br>        (result) =&gt; {<br>          this.setState({<br>            employees: result.employees<br>          })<br>        },<br>        (error) =&gt; {<br>          this.setState({ error })<br>        }<br>      )<br>  }</em></pre><pre><em>  render() {<br>    const { error, employees } = this.state<br>    if (error) {<br>      return &lt;div&gt;Error: {error.message}&lt;/div&gt;;<br>    } else {<br>      return (<br>        &lt;ul&gt;<br>          {employees.map(employee =&gt; (<br>            &lt;li key={employee.name}&gt;<br>              {employee.name}-{employee.experience}<br>            &lt;/li&gt;<br>          ))}<br>        &lt;/ul&gt;<br>      )<br>    }<br>  }<br>}</em></pre><h3>Q-17: What is React Router?</h3><p><em>React Router is a powerful routing library built on top of React that helps you add new screens and flows to your application incredibly quickly, all while keeping the URL in sync with what’s being displayed on the page.</em></p><h3>Q-18: How to get query parameters in React Router v4?</h3><p><em>The ability to parse query strings was taken out of React Router v4 because there have been user requests over the years to support different implementation. So the decision has been given to users to choose the implementation they like. The recommended approach is to use query strings library.</em></p><pre><em>const queryString = require(&#39;query-string&#39;);<br>const parsed = queryString.parse(props.location.search);</em></pre><p><em>You can also use </em><em>URLSearchParams if you want something native:</em></p><pre><em>const params = new URLSearchParams(props.location.search)<br>const foo = params.get(&#39;name&#39;)</em></pre><p>You should use a <em>polyfill</em> for IE11.</p><h3>Q-19: What are the two ways of formatting in React Intl?</h3><p><em>The library provides two ways to format strings, numbers, and dates: react components or an API.</em></p><pre><em>&lt;FormattedMessage<br>  id={&#39;account&#39;}<br>  defaultMessage={&#39;The amount is less than minimum balance.&#39;}<br>/&gt;</em></pre><pre><em>const messages = defineMessages({<br>  accountMessage: {<br>    id: &#39;account&#39;,<br>    defaultMessage: &#39;The amount is less than minimum balance.&#39;,<br>  }<br>})</em></pre><pre><em>formatMessage(messages.accountMessage)</em></pre><h3>Q-20: How to format date using React Intl?</h3><p><em>The </em><em>injectIntl() higher-order component will give you access to the </em><em>formatDate() method via the props in your component. The method is used internally by instances of </em><em>FormattedDate and it returns the string representation of the formatted date.</em></p><pre><em>import { injectIntl, intlShape } from &#39;react-intl&#39;</em></pre><pre><em>const stringDate = this.props.intl.formatDate(date, {<br>  year: &#39;numeric&#39;,<br>  month: &#39;numeric&#39;,<br>  day: &#39;numeric&#39;<br>})</em></pre><pre><em>const MyComponent = ({intl}) =&gt; (<br>  &lt;div&gt;{`The formatted date is ${stringDate}`}&lt;/div&gt;<br>)</em></pre><pre><em>MyComponent.propTypes = {<br>  intl: intlShape.isRequired<br>}</em></pre><pre><em>export default injectIntl(MyComponent)</em></pre><h3>Q-21: What is Jest?</h3><p><em>Jest</em> is a JavaScript unit testing framework created by Facebook based on Jasmine and provides automated mock creation and a jsdom environment. It&#39;s often used for testing components.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ecc07d3a5ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[10 JAVASCRIPT INTERVIEW QUESTIONS]]></title>
            <link>https://medium.com/@mahmud886/10-javascript-interview-questions-ee31a3c1a742?source=rss-8e6ba8805fe7------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee31a3c1a742</guid>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[javascript-interview]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Iqbal Mahmud]]></dc:creator>
            <pubDate>Wed, 13 May 2020 15:33:04 GMT</pubDate>
            <atom:updated>2020-05-13T15:33:04.373Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*utN6q3uKPz6TpmjffgW_-w.png" /></figure><h3><strong>Q-1: What is </strong><strong>WeakMap in ES6?</strong></h3><p><em>The </em><em>WeakMap is same as </em><em>Map where it is a collection of key/value pairs. But in </em><em>WeakMap, the </em><strong><em>keys must be objects</em></strong><em> 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 </em><em>WeakMap API is the same as the </em><em>Map API.</em></p><p><em>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 </em><em>Map.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*c9cZsauEpReab9QX9-vUTQ.png" /><figcaption>WeakMap</figcaption></figure><h3>Q-2: <strong>What is </strong><strong>Set?</strong></h3><p><em>Set 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.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*H6B5ZeuM3BUpvVy9pOrslQ.png" /><figcaption>Set</figcaption></figure><p><em>Also, </em><em>NaN and </em><em>undefined can also be stored in a </em><em>Set. </em><em>NaN is considered the same as </em><em>NaN (even though </em><em>NaN !== NaN).</em></p><h3>Q-3: <strong>What is Generator function?</strong></h3><p><em>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.</em></p><p><em>A generator function returns an </em><strong><em>iterable object</em></strong><em> when it’s called. It is written using the new </em><em>* syntax as well as the new yield keyword introduced in ES6.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*2bE_PhsOkNyLVmxI610UCA.png" /><figcaption>Generator function</figcaption></figure><p><em>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.</em></p><h3>Q-4: <strong>What is </strong><strong>WeakSet?</strong></h3><p><em>The </em><em>WeakSet object lets you store weakly held objects in a collection.</em></p><p><em>WeakSet objects are collections of objects. An object in the </em><em>WeakSet may occur only once; it is unique in the </em><em>WeakSet&#39;s collection. The main differences to the </em><em>Set object are:</em></p><ul><li><em>Unlike </em><em>Set, </em><em>WeakSets are collections of </em><strong><em>objects only</em></strong><em> and not of arbitrary values of any type.</em></li><li><em>The </em><em>WeakSet is weak: References to objects in the collection are held weakly. If there is no other reference to an object stored in the </em><em>WeakSet, they can be garbage collected. That also means that there is no list of current objects stored in the collection. WeakSets are not enumerable.</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*roMBWV2nGJIIPNPeG67zhQ.png" /><figcaption>WeakSet</figcaption></figure><h3>Q-5: What will be the output of the code below?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*Kf7AMPxJklsYVGaINX7Blg.png" /></figure><p><em>The output would be </em><em>5. When we use the </em><em>delete operator to delete an array element, the array length is not affected from this. This holds even if you deleted all elements of an array using the </em><em>delete operator.</em></p><p><em>In other words, when the </em><em>delete operator removes an array element, that deleted element is not longer present in array. In place of value at deleted index </em><em>undefined x 1 in chrome and </em><em>undefined is placed at the index. If you do </em><em>console.log(trees) output </em><em>[&quot;xyz&quot;, &quot;xxxx&quot;, &quot;test&quot;, undefined × 1, &quot;apple&quot;] in Chrome and in Firefox </em><em>[&quot;xyz&quot;, &quot;xxxx&quot;, &quot;test&quot;, undefined, &quot;apple&quot;]</em></p><h3>Q-6: How can we calculate the length of the above associative array’s counterArray?</h3><p><em>There are no in-built functions and properties available to calculate the length of associative array object here. However, there are other ways by which we can calculate the length of an associative array object. In addition to this, we can also extend an </em><em>Object by adding a method or property to the prototype in order to calculate length. However, extending an object might break enumeration in various libraries or might create cross-browser issues, so it&#39;s not recommended unless it&#39;s necessary. Again, there are various ways by which we can calculate length.</em></p><p><em>Object has the </em><em>keys method which can be used to calculate the length of an object:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*1cMeqHJvWxji6aRdfANRHw.png" /></figure><p><em>We can also add a </em><em>length method directly on </em><em>Object:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*9NA28RHoq542PADRV0TVZQ.png" /></figure><h3>Q-7: How do you add an element at the begining of an array? How do you add one at the end?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*HSqZ34di4xlE1t7Wba2ebg.png" /></figure><h3>Q-8: What will the following code output and why?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*FxJS2hsnk8zH3Fl7JD2MDw.png" /></figure><p><em>Output to the console will be “3”.</em></p><p><em>There are three closures in the example, each with it’s own </em><em>var b declaration. When a variable is invoked closures will be checked in order from local to global until an instance is found. Since the </em><em>inner closure has a </em><em>b variable of its own, that is what will be output.</em></p><p><em>Furthermore, due to hoisting the code in inner will be interpreted as follows:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/525/1*yoxonKXTLdwNT8fsDXM4Vw.png" /></figure><h3>Q-9: What is NaN? What is its type? How can you reliably test if a value is equal to NaN?</h3><p><em>The </em><em>NaN property represents a value that is “not a number”. This special value results from an operation that could not be performed either because one of the operands was non-numeric (e.g., </em><em>&quot;abc&quot; / 4), or because the result of the operation is non-numeric.</em></p><p><em>While this seems straightforward enough, there are a couple of somewhat surprising characteristics of </em><em>NaN that can result in hair-pulling bugs if one is not aware of them.</em></p><p><em>For one thing, although </em><em>NaN means “not a number”, its type is, believe it or not, </em><em>Number:</em></p><pre><em>console.log(typeof NaN === &quot;number&quot;);  // logs &quot;true&quot;</em></pre><p><em>Additionally, </em><em>NaN compared to anything – even itself! – is false:</em></p><pre><em>console.log(NaN === NaN);  // logs &quot;false&quot;</em></pre><p><em>A semi-reliable way to test whether a number is equal to NaN is with the built-in function </em><em>isNaN(), but even using </em><em>isNaN() is an imperfect solution.</em></p><p><em>A better solution would either be to use </em><em>value !== value, which would only produce true if the value is equal to NaN. Also, ES6 offers a new </em><em>Number.isNaN() function, which is a different and more reliable than the old global </em><em>isNaN() function.</em></p><h3><strong>Q-10: What is the significance, and what are the benefits, of including </strong><strong>&#39;use strict&#39; at the beginning of a JavaScript source file?</strong></h3><p><em>The short and most important answer here is that </em><em>use strict is a way to voluntarily enforce stricter parsing and error handling on your JavaScript code at runtime. Code errors that would otherwise have been ignored or would have failed silently will now generate errors or throw exceptions. In general, it is a good practice.</em></p><p><em>Some of the key benefits of strict mode include:</em></p><ul><li><em>Makes debugging easier. Code errors that would otherwise have been ignored or would have failed silently will now generate errors or throw exceptions, alerting you sooner to problems in your code and directing you more quickly to their source.</em></li><li><em>Prevents accidental globals. Without strict mode, assigning a value to an undeclared variable automatically creates a global variable with that name. This is one of the most common errors in JavaScript. In strict mode, attempting to do so throws an error.</em></li><li><em>Eliminates </em><em>this coercion. Without strict mode, a reference to a </em><em>this value of null or undefined is automatically coerced to the global. This can cause many headfakes and pull-out-your-hair kind of bugs. In strict mode, referencing a a </em><em>this value of null or undefined throws an error.</em></li><li><em>Disallows duplicate parameter values. Strict mode throws an error when it detects a duplicate named argument for a function (e.g., </em><em>function foo(val1, val2, val1){}), thereby catching what is almost certainly a bug in your code that you might otherwise have wasted lots of time tracking down.</em></li><li><em>Note: It used to be (in ECMAScript 5) that strict mode would disallow duplicate property names (e.g. </em><em>var object = {foo: &quot;bar&quot;, foo: &quot;baz&quot;};) but as of ECMAScript 2015 this is no longer the case.</em></li><li><em>Makes eval() safer. There are some differences in the way </em><em>eval() behaves in strict mode and in non-strict mode. Most significantly, in strict mode, variables and functions declared inside of an </em><em>eval() statement are not created in the containing scope (they are created in the containing scope in non-strict mode, which can also be a common source of problems).</em></li><li><em>Throws error on invalid usage of </em><em>delete. The </em><em>delete operator (used to remove properties from objects) cannot be used on non-configurable properties of the object. Non-strict code will fail silently when an attempt is made to delete a non-configurable property, whereas strict mode will throw an error in such a case.</em></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee31a3c1a742" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[10 Interview Questions
Every JavaScript Developer Should Know]]></title>
            <link>https://medium.com/@mahmud886/10-interview-questions-every-javascript-developer-should-know-f25e09768daf?source=rss-8e6ba8805fe7------2</link>
            <guid isPermaLink="false">https://medium.com/p/f25e09768daf</guid>
            <dc:creator><![CDATA[Iqbal Mahmud]]></dc:creator>
            <pubDate>Tue, 12 May 2020 16:40:54 GMT</pubDate>
            <atom:updated>2020-05-12T16:40:54.765Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*UK108sytbwlncKIuUs7P6A.jpeg" /></figure><h3>Question No-1: What are Promises?</h3><p><em>Promises are one way in handling asynchronous operations in JavaScript. It represents the value of an asynchronous operation. Promises was made to solve the problem of doing and dealing with async code before promises we’re using callbacks.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*wViEb-vZqADmRCgRSAwusQ.png" /></figure><p><em>The problem with this approach if we have another async operation inside the callback and another. We will have a code that is messy and unreadable. This code is called Callback Hell.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*0I-HKpYjB8pH8OrqKZ0tmQ.png" /></figure><p><em>If we use promises in this code it will be more readable and easy to understand and easy to maintain.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*H-UqrdU5nfNMyMsxVBS45g.png" /></figure><p><strong><em>Promises have 3 different states.</em></strong></p><p><strong><em>Pending</em></strong><em> — The initial state of a promise. The promise’s outcome has not yet been known because the operation has not been completed yet.</em></p><p><strong><em>Fulfilled</em></strong><em> — The async operation is completed and successful with the resulting value.</em></p><p><strong><em>Rejected</em></strong><em> — The async operation has failed and has a reason on why it failed.</em></p><p><strong><em>Settled</em></strong><em> — If the promise has been either Fulfilled or Rejected.</em></p><p><em>The Promise constructor has two parameters which are functions </em><em>resolve and </em><em>reject respectively.<br>If the async operation has been completed without errors call the </em><em>resolve function to resolve the promise or if an error occurred<br>call the </em><em>reject function and pass the error or reason to it.<br>We can access the result of the fulfilled promise using the </em><em>.then<br>method and we catch errors in the </em><em>.catch method. We chain multiple async promise operations in the </em><em>.then method because the </em><em>.then method returns a Promise just like the example in the image e above.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*w5dr1V7zG2V_nSqONL9owg.png" /></figure><p><em>We can make a helper func that converts an async operation with a callback to promise. It works like the promisify utility function from the node core module util.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*ZV753Xf5ErBbsDT6xwmnuw.png" /></figure><h3>Question No-2: What are Template Literals?</h3><p><strong><em>Template Literals</em></strong><em> are a new way of making </em><strong><em>strings</em></strong><em> in JavaScript. We can make </em><strong><em>Template Literal</em></strong><em> by using the backtick or back-quote symbol.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*T4kLmiK6arImFp9Si7J5mw.png" /></figure><p><em>In the ES5 version, we need to escape the </em><em>&#39; using the </em><em>\ to escape the normal functionality of that symbol which in this case is to finish that string value. In Template Literals, we don&#39;t need to do that.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*6SrudRUS4dvtEGHiuJJIHQ.png" /></figure><p><em>In the ES5 version, we need to add this </em><em>\n to have a new line in our string. In Template Literals, we don&#39;t need to do that.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*X-GWywU5eaRTDQtMYQmeeA.png" /></figure><pre><em>In the ES5 version, If we need to add an expression or value in a string we need to use the </em><em>+ or string concatenation operator. In Template Literals, we can embed an expression using </em><em>${expr} which makes it cleaner than the ES5 version.</em></pre><h3>Question No-3: What is Object Destructuring?</h3><p><strong><em>Object Destructuring</em></strong><em> is a new and cleaner way of </em><strong><em>getting</em></strong><em> or </em><strong><em>extracting</em></strong><em> values from an object or an array.</em></p><p><em>Suppose we have an object that looks like this.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*PeJz-LLD-7Q9x41_ke074w.png" /></figure><p><em>The old way of getting properties from an object is we make a variable that has the same name as the object property. This way is a hassle because we’re making a new variable for every property. Imagine we have a big object with lots of properties and methods using this way in extracting properties will be irritating.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*A_JuHgl9ROKSg4_9eQ0K2w.png" /><figcaption>1</figcaption></figure><p><em>If we use </em><strong><em>object destructuring</em></strong><em> it looks cleaner and takes a little time than the old way. The syntax for object destructuring is that if we are getting properties in an object we use the </em><em>{} and inside that, we specify the properties we want to extract and if we are getting data from an array we use the </em><em>[].</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*oxstc338hsEiPE5i3BCS3Q.png" /></figure><p><em>If we want to change the variable name we want to extract we use the </em><em>propertyName:newName syntax. In this example the value of </em><em>fName variable will hold the value of the </em><em>firstName property and </em><em>lName variable will hold the value of the </em><em>lastName property.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*h6g07OhWrABsdNu4fXisPw.png" /></figure><p><em>We can also have default values when destructuring. In this example, if the </em><em>firstName property holds an </em><em>undefined value in the object then when we destructure the </em><em>firstName variable will hold a default of </em><em>&quot;Snigdho&quot;.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*J-0bTPvWL4dCZ_2LPelU0g.png" /></figure><h3>Question No-4: What is async/await and How does it work?</h3><p><strong><em>async/await </em></strong><em>is the new way of writing asynchronous or non-blocking code in </em><strong><em>JavaScript’s</em></strong><em>. It is built on top of </em><strong><em>Promises</em></strong><em>. It makes writing asynchronous code more readable and cleaner than<br></em><strong><em>Promises</em></strong><em> and </em><strong><em>Callbacks</em></strong><em>. But you must learn the basics of </em><strong><em>Promises</em></strong><em> before using this feature because as I said earlier it is built on top of </em><strong><em>Promises</em></strong><em> which means is still uses </em><strong><em>Promises</em></strong><em> under the hood.</em></p><p><em>Using Promises.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*WM1fgy8z-2k8i7HMdeRKXQ.png" /></figure><p><em>Using Async/Await.</em></p><p><strong><em>Note</em></strong><em>: We’re using the old try/catch statement to </em><strong><em>catch</em></strong><em> any errors that happened in any of those async operations inside the try statement.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*wzpoPKkzYlTfzhUaEgr9pw.png" /></figure><p><strong><em>Note</em></strong><em>: The async keyword before the function declaration makes the function return implicitly a </em><strong><em>Promise</em></strong><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/713/1*E3dBu7BDZVTWgOjEbeKwCA.png" /></figure><p><strong><em>Note</em></strong><em>: The await keyword can </em><strong><em>only</em></strong><em> be used inside an </em><strong><em>async function</em></strong><em>. Using await keyword in any other function which is not an </em><strong><em>async function</em></strong><em> will throw an error. The await keyword </em><strong><em>awaits</em></strong><em> the right-hand side expression (presumably a </em><strong><em>Promise</em></strong><em>) to return before executing the next line of code.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*CY4ToZKfbIhbOb5NJ63M9Q.png" /></figure><h3>Question No-5: What are Default Parameters?</h3><p><strong><em>Default Parameters</em></strong><em> is a new way of defining default variables in </em><strong><em>JavaScript</em></strong><em> it is available in the </em><strong><em>ES6</em></strong><em> or </em><strong><em>ECMAScript 2015</em></strong><em> Version.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*N3CCz9VT-o7Wxnk5fu-L6A.png" /></figure><p><strong><em>We can also use Destructuring in Default Paremeters.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*N1EebZvtLzFInx19xb7B3g.png" /></figure><p><em>We can also use the parameters defined first to the parameters defined after them.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*3CPMYbO1621RQBL4Q8BpCQ.png" /></figure><h3>Question No-6: What are Wrapper Objects?</h3><p><strong><em>Primitive Values</em></strong><em> like </em><em>string,</em><em>number and </em><em>boolean with the exception of </em><em>null and </em><em>undefined have properties and methods even though they are not </em><em>objects.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*lc3GgSX7LheZvgmx1oXXXw.png" /></figure><p><em>name is a </em><em>primitive string value that has no properties and methods but in this example we are calling a </em><em>toUpperCase() method which does not throw an error but returns SNIGDHO.</em></p><p><em>The reason for this is that the </em><em>primitive value is temporarily converted or coerce to an </em><em>object so the </em><em>name variable behaves like an </em><em>object. Every </em><em>primitive except </em><em>null and </em><em>undefined have </em><strong><em>Wrapper Objects</em></strong><em>. The Wrapper Objects are </em><em>String,</em><em>Number,</em><em>Boolean,</em><em>Symbol and </em><em>BigInt. In this case, the </em><em>name.toUpperCase() invocation, behind the scenes it looks like this.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*lhRN0E6Ibx51IwMPq-VFpA.png" /></figure><p><em>The newly created object is immediately discarded after we finished accessing a property or calling a method.</em></p><h3>Question No-7: What are the ways to deal with Asynchronous Code in JavasScript?</h3><ul><li><em>Callbacks</em></li><li><em>Promises</em></li><li><em>async/await</em></li><li><em>Libraries like async.js, bluebird, q, co</em></li></ul><h3>Question No-8: How many ways can a function be invoked?</h3><p><em>There are 4 ways that a function can be invoked in </em><strong><em>JavaScript</em></strong><em>. The </em><strong><em>invocation</em></strong><em> determines the value of </em><em>this or the &quot;owner&quot; object of that function.</em></p><p><strong><em>Invocation as a function</em></strong><em> — If a function isn’t invoked as a method, as a constructor or with the </em><em>apply, </em><em>call methods then it is </em><strong><em>invoked as a function</em></strong><em>. The &quot;owner&quot; object of this function will be the </em><em>window object.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*R8u1871CoSUIWepiiH-_og.png" /></figure><p><strong><em>Invocation as a method</em></strong><em> — If a property of an object has a value of a function we call it a </em><strong><em>method</em></strong><em>. When that </em><strong><em>method</em></strong><em> is invoked the </em><em>this value of that method will be that object.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*PI5Y-UqL3S5PZ2bjVIH30Q.png" /></figure><p><strong><em>Invocation as a constructor</em></strong><em> — If a function was invoked with a </em><em>new keyword before it then it&#39;s called a </em><em>function constructor. An empty object will be created and </em><em>this will point to that object.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*qM8Ubf_WEzs55BhYl39qTQ.png" /></figure><p><strong><em>Invocation with the </em></strong><strong><em>apply and </em></strong><strong><em>call methods</em></strong><em> - If we want to explicitly specify the </em><em>this value or the &quot;owner&quot; object of a function we can use these methods. These methods are available for all functions.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*rtaGtu_ypqF7i5YBLEFbbw.png" /></figure><h3>Question No-9: What does the new keyword do?</h3><p><em>The </em><em>new keyword is used with constructor functions to make objects<br>in </em><strong><em>JavaScript</em></strong><em>.</em></p><p><em>Suppose we have an example code below.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*RtBziNsgtrEeK3GJvqk6GA.png" /></figure><p><em>The </em><em>new keyword does 4 things.</em></p><ul><li><em>Creates an empty object.</em></li><li><em>Assigns that empty object to the </em><em>this value.</em></li><li><em>The function will inherit from </em><strong><em>functionName.prototype</em></strong><em>.</em></li><li><em>Returns the </em><em>this if no Explicit </em><em>return statement is used.</em></li></ul><p><em>In the above image, it will first create an empty object </em><em>{} then<br>it will the </em><em>this value to that empty object </em><em>this = {} and add properties to that </em><em>this object. Because we don&#39;t have a explicit </em><em>return statement it automatically returns the </em><em>this for us.</em></p><h3>Question No-10: What’s Event Capturing?</h3><p><em>When an </em><strong><em>event</em></strong><em> occurs on a </em><strong><em>DOM</em></strong><em> element, that </em><strong><em>event</em></strong><em> does not entirely occur on that just one element. In </em><strong><em>Capturing Phase</em></strong><em>, the event starts from the </em><em>window all the way down to the element that triggered the event.</em></p><p><em>If we have an example markup like this.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*3mpwwdSVN90AkH5UBf7-pw.png" /></figure><p>And js code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*Cy7Ke2Asz5RQAiwGIVPobw.png" /></figure><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f25e09768daf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Top 20 Interview Questions For HTML and CSS.]]></title>
            <link>https://medium.com/@mahmud886/top-20-interview-questions-for-html-and-css-aa23c129cef7?source=rss-8e6ba8805fe7------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa23c129cef7</guid>
            <category><![CDATA[html-interview-questions]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[css-interview-questions]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Iqbal Mahmud]]></dc:creator>
            <pubDate>Mon, 11 May 2020 17:10:50 GMT</pubDate>
            <atom:updated>2020-05-11T17:10:50.754Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*IDkvY9BFl3PzKJ5iUUFq0A.jpeg" /></figure><h3>PART-1 HTML</h3><h3>Question No-1: What are the new features introduced in HTML 5?</h3><p><em>HTML 5 introduces a number of new elements and attributes that help in building an attractive web Site, that we see nowadays.</em></p><p><em>It supports following new features.</em></p><ul><li><strong><em>New Semantic Elements </em></strong><em>— These are like &lt;header&gt;, &lt;footer&gt;, and &lt;section&gt;.</em></li><li><strong><em>Forms 2.0 </em></strong><em>— It contains improvements to HTML web forms. It has introduced new attributes for the &lt;input&gt; tag.</em></li><li><strong><em>Persistent Local Storage </em></strong><em>— With HTML5, it is possible to achieve this, without resorting to third-party plugins.</em></li><li><strong><em>WebSocket</em></strong><em> — It facilitates setting up a bidirectional communication for web applications.</em></li><li><strong><em>Server-Sent Events(SSE)</em></strong><em> — These events got introduced in HTML5. The direction of the flow of the execution of these events is from the server to the Web Browser.</em></li><li><strong><em>Canvas </em></strong><em>— It supports a two-dimensional drawing surface that is programmable using JavaScript.</em></li><li><strong><em>Audio &amp; Video </em></strong><em>— It allows embedding audio or video on the web pages without resorting to third-party plugins.</em></li><li><strong><em>Geolocation </em></strong><em>— It facilitates the visitors to share their physical location with the web application.</em></li><li><strong><em>Microdata </em></strong><em>— It allows building our personal vocabulary beyond HTML5 and extends our web pages with those custom semantics.</em></li><li><strong><em>Drag and drop</em></strong><em> — It supports to Drag and drop the items from one location to another location on the same Web page.</em></li></ul><h3>Question No-2: What are the new Form elements made available in HTML 5?</h3><p><em>When we want to collect some data from the person visiting our site, we use HTML Forms. An example is, the user has to enter his name, email id when he registers for the first time.</em></p><p><em>A form takes input from the site visitor and then posts it to a back-end application such as CGI, ASP Script or PHP script. The back-end application will then perform required processing on the passed data based on defined business logic inside the application.</em></p><p><em>There are various form elements available in earlier version of HTML like, text fields, text area fields, drop-down menus, radio buttons, checkboxes, etc.</em></p><p><em>HTML5 provides the support of some new Form elements that are as follows.</em></p><ul><li><strong><em>&lt;datalist&gt; </em></strong><em>— It represents a list of pre-defined options for input controls.</em></li><li><strong><em>&lt;keygen&gt;</em></strong><em> — It defines a key-pair generator field (for forms).</em></li><li><strong><em>&lt;output&gt;</em></strong><em> — It represents the result of the calculation.</em></li></ul><h3>Question No-3: What is a semantic element in HTML5? Also, explain the difference between semantic and non-semantic elements?</h3><p><em>Semantic elements are one of the new features that are part of HTML5. They intend to help the developers in quickly creating the page structure.</em></p><p><em>A semantic element has its meaning expressed to both the browser and the developer. Also, all the modern browsers support this feature. However, it is possible for a developer to train old browsers to handle unknown elements.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*sYxjAk7Ii4b8mran8tZMYg.png" /></figure><p><em>Here is the list of some of the commonly used HTML5 Semantic Elements.</em></p><ul><li><strong><em>&lt;article&gt;</em></strong></li><li><strong><em>&lt;figcaption&gt;</em></strong></li><li><strong><em>&lt;figure&gt;</em></strong></li><li><strong><em>&lt;header&gt;</em></strong></li><li><strong><em>&lt;footer&gt;</em></strong></li><li><strong><em>&lt;nav&gt;</em></strong></li><li><strong><em>&lt;section&gt;</em></strong></li><li><strong><em>&lt;article&gt;</em></strong></li><li><strong><em>&lt;aside&gt;</em></strong></li><li><strong><em>&lt;summary&gt;</em></strong></li></ul><h4><em>The difference — Semantic Vs. Non-semantic.</em></h4><p><strong><em>Semantic</em></strong><em> — These elements clearly describe their content like </em><strong><em>&lt;img&gt;</em></strong><em>, </em><strong><em>&lt;form&gt;</em></strong><em>, </em><strong><em>&lt;table&gt;</em></strong><em> etc.</em></p><p><strong><em>Non-semantic </em></strong><em>— These elements are without any definition. They don’t describe anything about their structure such as </em><strong><em>&lt;span&gt; </em></strong><em>and </em><strong><em>&lt;div&gt;</em></strong><em>.</em></p><h3>Question No-4: What is HTML5 Graphics?</h3><p><em>In HTML5, there are two types of graphics.</em></p><h4><em>Scalable Vector Graphics (SVG).</em></h4><ul><li><em>The HTML5 </em><strong><em>&lt;svg&gt;</em></strong><em> element is a container for </em><strong><em>SVG graphics</em></strong><em>. It provides several methods for drawing boxes, paths, text, circles, and graphic images.</em></li><li><strong><em>SVG</em></strong><em> is beneficial as nowadays, people are using high-resolution devices (iPads and Monitors), so it becomes impressive as designs, logos, and charts scale according to the requirement, maintaining the picture quality.</em></li><li><strong><em>SVG is XML</em></strong><em> based, which means that every element is available within the </em><strong><em>SVG DOM.</em></strong><em> It treats every shape as an object. If the user changes the attributes of any </em><strong><em>SVG</em></strong><em> object, the browser will automatically re-render the shape.</em></li></ul><h4><em>Canvas.</em></h4><ul><li><em>It is a rectangular area on the </em><strong><em>HTML</em></strong><em> page for drawing graphics on the fly, using JavaScript.</em></li><li><em>The default size of the canvas is 300 PX × 150 PX (width × height).</em></li><li><em>The </em><strong><em>HTML</em></strong><em> tag &lt;canvas&gt; is a container for the Canvas graphics. Canvas gets executed on the pixel by pixel basis.</em></li><li><em>In Canvas, browser forgets the graphic, after drawing it. If the user tries to modify it, the entire scene needs to be redrawn, including all the objects present in the graphic.</em></li></ul><h3>Question No-5: How can we create a new HTML element?</h3><p><em>We can even create new elements for the document as follows.</em></p><pre><em>&lt;script&gt;<br>document.createElement﴾&quot;myElement&quot;﴿<br>&lt;/script&gt;</em></pre><p><em>It can be used in the HTML as.</em></p><pre><em>&lt;myElement&gt;hello&lt;/myElement&gt;</em></pre><h3>Question No-6: What is HTML5 Web Storage?</h3><p><strong><em>HTML5</em></strong><em> Web Storage, also known as </em><strong><em>DOM</em></strong><em> 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 </em><strong><em>HTTP</em></strong><em>. It allows the web pages to store the data locally in the user’s browser.</em></p><p><em>Following are the advantages of </em><strong><em>HTML5</em></strong><em> Web Storage.</em></p><ul><li><em>It can store 5 to 10 MB data. That is far more than what cookies allow.</em></li><li><strong><em>HTML5</em></strong><em> never transfers Web storage data with any </em><strong><em>HTTP</em></strong><em> request. Thus creating less overhead than cookies and in turn, increase the performance of the application.</em></li><li><em>Apps can work both online and offline.</em></li><li><em>This </em><strong><em>API</em></strong><em> is easy to learn and use.</em></li></ul><h3>Question No-7: Explain the key differences between localStorage and sessionStorage objects?</h3><p><em>Following are the key differences between </em><strong><em>localStorage</em></strong><em> and </em><strong><em>sessionStorage</em></strong><em> objects.</em></p><ul><li><em>The </em><strong><em>localStorage</em></strong><em> object stores the data without an expiry date. However, </em><strong><em>sessionStorage</em></strong><em> object stores the data for only one session.</em></li><li><em>In the case of a </em><strong><em>localStorage</em></strong><em> object, data will not delete when the browser window closes. However, the data gets deleted, if the browser window closes, in the case of </em><strong><em>sessionStorage</em></strong><em> objects.</em></li><li><em>The data in </em><strong><em>sessionStorage</em></strong><em> is accessible only in the current window of the browser. But the data in the </em><strong><em>localStorage</em></strong><em> can be shared between multiple windows of the browser.</em></li></ul><h3>Question No-8: What is a Manifest file?</h3><p><em>A Manifest file is a simple text file, that tells the browser what to cache and what not to cache.</em></p><p><em>A Manifest file contains three Sections as</em></p><ul><li><strong><em>CACHE MANIFEST </em></strong><em>— HTML5 performs the caching of files listed under this section after<br>they get downloaded for the first time.</em></li><li><strong><em>NETWORK</em></strong><em> — Files listed here, always need a connection to the server. The browser can never cache them.</em></li><li><strong><em>FALLBACK </em></strong><em>— Files listed here specify the fallback pages, if any page in it is not accessible.</em></li></ul><h3>Question No-9: What is a Web Worker? How does it work?</h3><p><em>JavaScript will hang the browser if it has to handle UI events, query large amounts of API data for processing, and manipulate the DOM simultaneously.<br>Web Workers handle this situation by doing all the high computation tasks without interrupting the user interface. They do this by running on separate threads. Thus we can say that.</em></p><ul><li><em>A web worker is a script, which runs in the background. It exists in external files.</em></li><li><em>The user can perform actions like clicking, selecting things and so on. Meanwhile, the Web worker runs in the background.</em></li><li><em>It is appropriate, to use Web worker for CPU intensive tasks.</em></li></ul><p><em>Since Web workers are in external files, they do not have access to the following JavaScript objects.</em></p><ul><li><strong><em>The window object</em></strong></li><li><strong><em>The document object</em></strong></li><li><strong><em>The parent object</em></strong></li></ul><h3>Question No-10: When should you use section, div or article?</h3><p><em>&lt;section&gt;, group of content inside is related to a single theme, and should appear as an entry in an outline of the page. It’s a chunk of related content, like a subsection of a long article, a major part of the page (eg the news section on the homepage), or a page in a webapp’s tabbed interface. A section normally has a heading (title) and maybe a footer too.</em></p><p><em>&lt;article&gt;, represents a complete, or self-contained, composition in a document, page, application, or site and that is, in principle, independently distributable or reusable, e.g. in syndication. This could be a forum post, a magazine or newspaper article, a blog entry, a user-submitted comment, an interactive widget or gadget, or any other independent item of content.</em></p><p><em>&lt;div&gt;, on the other hand, does not convey any meaning, aside from any found in its class, lang and title attributes.</em></p><h3>PART-2: CSS</h3><h3>Question No-1: <strong>Name all the modules which are used in the current version of CSS.</strong></h3><p><em>There are several modules in CSS as stated below:</em></p><ul><li><em>Selectors</em></li><li><em>Box Model</em></li><li><em>Backgrounds and Borders</em></li><li><em>Text Effects</em></li><li><em>2D / 3D Transformations</em></li><li><em>Animations</em></li><li><em>Multiple Column Layout</em></li><li><em>User Interface.</em></li></ul><h3>Question No-2: <strong>What is the CSS Box model and what are its elements?</strong></h3><p><em>The CSS box model is used to define the design and layout of elements of CSS.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CSL2YLWiUV_VlGCJnfygEA.png" /></figure><p><em>The elements are:</em></p><p><strong><em>Margin</em></strong><em> — It removes the area around the border. It is transparent.</em></p><p><strong><em>Border</em></strong><em> — It represents the area around the padding</em></p><p><strong><em>Padding</em></strong><em> — It removes the area around the content. It is transparent.</em></p><p><strong><em>Content</em></strong><em> — It represents content like text, images, etc.</em></p><h3>Question No-3: <strong>Write all the properties of the flexbox.</strong></h3><p><em>There are several properties of the </em><strong><em>flexbox</em></strong><em> that are used in the HTML webpage.</em></p><p><strong><em>They are:</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HGXoBi1rjUFrv7LBtynokQ.jpeg" /></figure><ul><li><em>flex-direction</em></li><li><em>flex-wrap</em></li><li><em>flex-flow</em></li><li><em>justify-content</em></li><li><em>align-items</em></li><li><em>align-content</em></li></ul><h3>Question No-4: <strong>What is the difference between padding and margin?</strong></h3><p><em>In CSS, the margin is the property by which we can create space around elements. We can even create space to the exterior defined borders.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*SZb5_1zgH_zzfJgJlaX34w.png" /></figure><p><strong><em>In CSS, we have margin property as follows:</em></strong></p><ul><li><em>margin-top</em></li><li><em>margin-right</em></li><li><em>margin-bottom</em></li><li><em>Margin-left</em></li></ul><p><strong><em>Margin property has some defined values as shown below.</em></strong></p><ul><li><strong><em>Auto </em></strong><em>— Using this property browser calculates the margin.</em></li><li><strong><em>Length </em></strong><em>— It sets the margin values in px,pt,cm etc.</em></li><li><strong><em>% </em></strong><em>— It sets the width % of the element.</em></li><li><strong><em>Inherit </em></strong><em>— By this property we can inherit the margin property from the parent element.</em></li></ul><p><em>In CSS, padding is the property by which we can generate space around an element’s content as well as inside any known border.</em></p><p><strong><em>CSS padding also has properties like,</em></strong></p><ol><li><em>Padding-top</em></li><li><em>Padding-right</em></li><li><em>Padding-bottom</em></li><li><em>Padding-left</em></li></ol><p><em>Negative values are not allowed in padding.</em></p><pre><em>div {<br>padding-top: 60px;<br>padding-right: 40px;<br>padding-bottom: 50px;<br>padding-left: 70px;<br>}</em></pre><h3>Question No-5: What are pseudo classes and what are they used for?</h3><p><em>Pseudo classes are similar to pseudo elements, but instead of styling a part of an element, they apply styles when an element is in a certain state. For example, you could style a button differently based on whether the user has their mouse pointer over it, or when they click the button.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*q-LieYmcheSGGfToDjlRlQ.png" /></figure><p><em>Another common use case is to style only certain occurrences of elements in a row. For example, styling the first tab in a series of tabs, or every second tab.</em></p><p><em>They all start with a single colon and look like this:</em></p><pre><em>.link:hover { ... }<br>.link:active { ... }<br>.tab:first-child { ... }<br>.tab:last-child { ... }<br>.avatar:nth-child(2n) { ... }</em></pre><h3>Question No-6: Should you use !important?</h3><p><em>When you’re wrestling with specificity, trying to override that one style, you may be tempted to add </em><strong><em>!important</em></strong><em> to your style. Think very carefully before you do so! It may seem harmless, but if you do this all over the place, you will soon find yourself in a big mess that you cannot get out of.</em></p><p><em>What </em><strong><em>!important</em></strong><em> does, is make that particular style have the highest specificity possible. Nothing else can override it, apart from another </em><strong><em>!important</em></strong><em>. You might be able to see where this is going, but once you start using them, you’ll almost certainly get into a position where you need to override a rule marked as </em><strong><em>!important</em></strong><em>, which forces you to use another one. And so the cycle continues.</em></p><pre><em>/* high specificity */<br>.large .navigation.navigation-large { <br>    font-size: 2em;<br>}</em></pre><pre><em>/* will override the above, but it&#39;s dangerous! */<br>.navigation {<br>    font-size: 3em </em><strong><em>!important</em></strong><em>;<br>}</em></pre><h3>Question No-7: <strong>What are the differences between relative and absolute in CSS?</strong></h3><p><em>The main difference between relative and absolute is that “relative” is used for the same tag in CSS and it means that if we write the left:10px then the padding will shift to 10px in the left while absolute is totally relative to the non-static parent.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*uZpvXFhGGFOroIm01viyxQ.png" /></figure><p><em>It means, if we write left:10px then the result will be 10px far from the left edge of the parent element.</em></p><h3>Question No-8: How would you use media queries in a mobile-first approach?</h3><p><em>There’s no way to avoid these nowadays, everyone expects their website to work on mobile devices, even if they don’t specifically ask for it.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*q0ietiqvOrA7HBSU6kLl4Q.jpeg" /></figure><p><em>The most common approach is the mobile-first one. All styles outside of media queries are targeted at mobile devices. Then, through progressively larger media queries, you can style larger screens one step at a time.</em></p><pre><em>/* mobile styles */<br>body { <br>    font-size: 1em;<br>}</em></pre><pre><em>/* desktop styles */<br>@media only screen and (min-width: 768px) {<br>    body {<br>        font-size: 1.5em;<br>    }<br>}</em></pre><h3>Question No-9: <strong>Differentiate between inline and block element.</strong></h3><p><em>Inline element does not have an element to set width and height and also it does not have the line break.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*49CBxFoJmCURot2AleXdmA.jpeg" /></figure><p><strong><em>Example:</em></strong><em> em, strong, etc.</em></p><p><strong><em>Block element specification:</em></strong></p><ul><li><em>They do have the line break.</em></li><li><em>They define the width by setting a container and also allow setting height.</em></li><li><em>It can also contain an element that occurs in the inline element.</em></li></ul><p><strong><em>Example:</em></strong></p><p><em>width and height<br>max-width and max-height<br>min-width and min-height<br>hi (i=1–6)- heading element<br>p- Paragraph element.</em></p><h3>Question No-10: Do you use any CSS preprocessors, and which do you prefer?</h3><p><em>If you’re working on a medium to large project, it’d be a good idea to use a CSS preprocessor. They allow you to write more concise CSS, split it up into multiple files and use a large number of very useful functions and mixins (you can even create your own!), along with variables.</em></p><p><em>The main players are Sass (also referred to as SCSS), LESS and Stylus, although arguably Sass is the biggest.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa23c129cef7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JAVASCRIPT REACT, DATA STRUCTURE & ALGORITHMS SUMMARY.]]></title>
            <link>https://medium.com/@mahmud886/javascript-react-data-structure-algorithms-summary-15871fb5e942?source=rss-8e6ba8805fe7------2</link>
            <guid isPermaLink="false">https://medium.com/p/15871fb5e942</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[data-structure-algorithm]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Iqbal Mahmud]]></dc:creator>
            <pubDate>Sun, 10 May 2020 06:34:52 GMT</pubDate>
            <atom:updated>2020-05-10T06:34:52.183Z</atom:updated>
            <content:encoded><![CDATA[<h3>REACT IS A JAVASCRIPT FRAMEWORK OR LIBRARY?</h3><p><em>React is a javaScript library, it is not same as framework. Framework provides total solution where React library is not a complete solution and you will need other libraries to sort out any solution. That’s why we can nominate React as a library but not as a framework.</em></p><h3>REACT DOM</h3><p><em>The Document Object Model is the browsers programming interface that treated HTML and XML documents as tree structures. By using the DOM API, we can change a document structure, style, and content.</em></p><h3>RECONCILIATION</h3><p><em>It is the process of recursively traversing a tree to know the DOM tag elements of a React application’s component tree. During this process, React goes through the following steps:</em></p><ul><li><em>Compares the previous internal instance with the next internal instance.</em></li><li><em>Updates the internal Instance (Virtual DOM).</em></li><li><em>Updates the actual DOM only at the node where there is an actual change.</em></li></ul><h3>COMPONENTS VS ELEMENTS</h3><p><em>You can be confused with this two words that are most commonly used in React guides and tutorials out there. As a react learner you must have to understand the difference between this two words.A react component is a template, blueprint or a global definition you can say. This can be either a function or a class with a render method.</em></p><p><em>A react element is what it gets returned from the components. It’s an object virtually describes the DOM nodes that a component represents. In function component, this element is the object that the function returns and in class components, this element is the object that the component’s render method returns.</em></p><h3>REACT COMPONENTS</h3><p><em>Components are one of the essential features of a React application. They are independent and reusable bits of code. Basically, they are like functions with a different syntax. They take props as inputs and returns the description of the UI as output. In React, there are two types of components.</em></p><p><strong>Class Components</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/0*SCLIOkUpf8UuAe-6.png" /><figcaption>Class Components</figcaption></figure><p><strong>Function Components</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/0*4Rei9FZCuktOlNOv.png" /><figcaption>Function Components</figcaption></figure><h3>REACT FRAGMENT</h3><p><em>A common pattern in React is for a component to return multiple elements. Fragments let you group a list of children without adding extra nodes to the DOM.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/0*7Jnr95N4aQMGSJN_.png" /><figcaption>REACT FRAGMENT</figcaption></figure><p><em>There is also a short and simple syntax for declaring them. It looks like empty tags.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/489/0*BozUJj4PGS072RBM.png" /></figure><h3>REACT UNDER THE HOOD</h3><p><em>React is a JavaScript library used to build user interfaces. There are several tools that power a React app.</em></p><ol><li><strong><em>Babel</em></strong><em>: It is a JavaScript transpiler used to convert code from one syntax to another. It is essential to React as is used to convert JSX into plain JS code.</em></li><li><strong><em>JSX</em></strong><em>: It is an extension to JavaScript, that allows us to write function calls in an HTML like syntax.</em></li><li><strong><em>Node.js</em></strong><em>: It is a JavaScript runtime environment built on Chrome’s V8 JavaScript engine. This allows us to execute JS outside the browser.</em></li><li><strong><em>NPM</em></strong><em>: It is a software register used as a package manager for JavaScript programming language.</em></li></ol><h3>BABEL</h3><p><em>Bable is a javascript compiler it compiles javascript ES2015+ code into older version javascript code for new or old browser and environment compatible. Babel can do fo you — <br>Transform syntax<br>Polyfill features that are missing in your target environment.<br>Source code transformations.</em></p><h3><strong>PROPS IN JSX</strong></h3><p><em>In React, ‘props’ is a special keyword that stands for properties and used for passing data between components. There are several ways to define props in JSX.<br>JavaScript Expressions<br>String Literals<br>Props Default to “True”<br>Spread Attributes</em></p><h3><strong>WHY NEED JSX?</strong></h3><p><em>JSX allows us to write HTML elements in JavaScript and place them in the DOM without any createElement() and appendChild() methods. JSX converts HTML tags into react elements. You are not required to use JSX, but JSX makes it easier to write React applications.<br>React uses JSX for templating instead of regular JavaScript. It is not necessary to use it, however, following are some pros that come with it:<br>It is faster because it performs optimization while compiling code to JavaScript.<br>It is also type-safe and most of the errors can be caught during compilation.<br>It makes it easier and faster to write templates, if you are familiar with HTML.</em></p><h3>ERROR HANDLING METHODS</h3><p><em>There are mainly two types of error handling methods in React. These methods are used in the error boundary mechanism.<br>static getDerivedStateFromError(error)<br>This method is useful for rendering a fallback UI after an error is thrown.<br>componentDidCatch(error, info)<br>This is useful for logging the error information for debugging purposes.</em></p><h3>WHAT IS LIFECYCLE METHOD IN REACT?</h3><p><em>React lifecycle methods are the series of events that happen from the birth of a React component to its death. Every component in React goes through a lifecycle of events. I like to think of them as going through a cycle of birth, growth, and death. Lifecyle methods execute in initial rendering or re-rendering phase.<br></em><strong><em>Example</em></strong><em>:<br>componentDidMount(), shouldComponentUpdate(), componentDidUpdate() etc.</em></p><h3>WHY IS UNIT TESTING NEEDED?</h3><p><em>Unit testing helps to make sure the code works correctly. Unit tests are a great way to do regression testing: simply run them every time you change something and make sure nothing breaks. Spotted a bug? Fix it and write a unit test to make sure it doesn’t happen again.<br>For your identified important parts of code, you need to write unit tests to make sure the code works.</em></p><h3>WHY NOT USE TRY / CATCH?</h3><p><em>try / catch is great but it only works for imperative code:<br> try {<br> showButton();<br> } catch (error) {<br>// …<br>}<br>However, React components are declarative and specify what should be rendered:<br>&lt;Button /&gt;<br>Error boundaries preserve the declarative nature of React and behave as you would expect. For example, even if an error occurs in a componentDidUpdate method caused by a setState somewhere deep in the tree, it will still correctly propagate to the closest error boundary.</em></p><h3>REACT HOOKS</h3><p><em>React hook is a way to use state and side effects in a react function components. By this means that hook allows us to easily manipulate the state of our functional component without needing to convert them class component. Hooks are a new addition in 16.8.</em></p><h3>RULES OF REACT HOOKS</h3><p><em>We need to understand the react rules before we dive into deep which are fundamental concepts.</em></p><ul><li><em>Only call Hooks at the top level. Don’t call Hooks inside loops, conditions, or nested functions.</em></li><li><em>Only call Hooks from React function components. Don’t call Hooks from regular JavaScript functions. (There is just one other valid place to call Hooks — your own custom Hooks. We’ll learn about them in a moment.)</em></li></ul><h3>REACT HOOK (OPTIMIZING FOR PERFORMANCE)</h3><p><em>Every developer always tries to optimize their application so that it can perform well. So there are some techniques to improve performance, like:</em></p><ul><li><em>Unnecessary re-render</em></li><li><em>Heavy computational calculation in the components repeatedly</em></li><li><em>And many more</em></li></ul><h3>WHY REACT HOOKS?</h3><p><em>React hooks were invented by the React team to introduce state management and side-effect in function component. Benefits of React hooks:</em></p><ul><li><em>Unnecessary Component Refactoring</em></li><li><em>Side Effect-logic</em></li><li><em>React’s Abstraction Hell</em></li><li><em>JavaScript Class Confusion reduced</em></li><li><em>Reducing the need for render props</em></li></ul><h3>USE CALLBACK()</h3><p><em>This useCallback() function is very help for optimization. This hook is useful when you have a component with a child frequently re-rendering. It returns a callback function that is memorized and that only changes if one dependency in the dependency tree changes.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/0*YW2RnrRMX8PMrwao.png" /><figcaption>USE CALLBACK()</figcaption></figure><h3>USESTATE()</h3><p><em>In React Hooks, useState() allows us to have state variables in functional components. It takes the initial value of the state as an argument and returns an array of two items. The first item is the current state and the second item is a function that updates the current state.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/0*E5j-vEpe03poFhWW.png" /><figcaption>USESTATE()</figcaption></figure><p><em>We can also make useState() clone using closures to understand how it actually works.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/0*lGFweXPwWbiQH4ty.png" /><figcaption>USESTATE()</figcaption></figure><h3>USEEFFECT()</h3><p><em>The useEffect() hook lets us perform side effects in function components. It takes a callback function as the first argument and an array of dependencies as the second argument. It executes the callback function if there is a change in any dependency values.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/0*_w0nnh1bbFoX9WWq.png" /><figcaption>USEEFFECT()</figcaption></figure><h3>CUSTOM HOOKS</h3><p><em>Hooks are nothing but JavaScript functions with some extra rules. Any JS function whose name starts with ‘use’ and that may call other hooks are known as custom hooks. They are useful for reusing stateful logic between components without repeating the same code or adding more components to the tree.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/0*VwdzcFHvweZYqTDe.png" /><figcaption>CUSTOM HOOKS</figcaption></figure><h3>HIGHER-ORDER COMPONENTS</h3><p><em>A Higher-Order Component ( HOC ) is an advanced technique to React for reusing component logic. HOC is common in third-party React libraries. A HOC is a function that takes a component and returns a new component. HOCs are not part of the React API. They are a pattern that emerges from React’s compositional nature.<br>const enhancedComponent = higherOrderComponent(WrappedComponent)</em></p><h3>REFS AND USEREF</h3><p><em>Refs are a special attribute that are available on all React components. They allow us to create a reference to a given element / component when the component mounts<br>useRef allows us to easily use React refs. We call useRef (at the top of the component) and attach the returned value to the element’s ref attribute to refer to it.<br>Once we create a reference, we use the current property to modify (mutate) the element’s properties. Or we can call any available methods on that element (like .focus() to focus an input).</em></p><h3>WHY WEB ACCESSIBILITY?</h3><p><em>Web Accessibility as a feature has been seen as a very wrong way of design thinking because by default it excludes a large number of web users. People who cannot see or for some reason cannot use a trackpad or a mouse pointer for instance should have as much rights and access as people who can.Web accessibility also benefits people without disabilities, these people may include:<br>People using mobile phones, smart watches, smart Tvs, and other devices with small screens, different screen modes etc.<br>Older people with changing abilities due to ageing.<br>People with “temporary disabilities” such as a broken arm or lost glasses.<br>People with siyuational limitations such as in bright sunlight or in an environment where the can not listen to audio.<br>People using a slow internet connection, who have limited or expensive bandwidth.</em></p><h3>DON’T USE HOCS INSIDE THE RENDER METHOD</h3><p><em>React’s the diffing algorithm which called reconciliation uses component identity to determine whether it should update the existing subtree or mount a new one.<br>If the component returned from render is identical (===) to the component from the previous render, React recursively updates the subtree by diffing it with<br>the new one. If they’re not equal, the previous subtree is unmounted completely.<br>We can also do it inside a component’s lifecycle methods or its constructor.</em></p><h3>WHAT ARE DATA STRUCTURES?</h3><p><em>Data structures, at a high level, are techniques for storing and organizing data that make it easier to modify, navigate, and access. Data structures determine how data is collected, the functions we can use to access it, and the relationships between data. Data structures are used in almost all areas of computer science and programming, from operating systems to basic vanilla code to artificial intelligence.</em></p><p><em>Data structures enable us to:</em></p><ul><li><em>Manage and utilize large datasets</em></li><li><em>Search for particular data from a database</em></li><li><em>Design algorithms that are tailored towards particular programs</em></li><li><em>Handle multiple requests from users at once</em></li><li><em>Simplify and speed up data processing</em></li></ul><p><em>Data structures are vital for efficient, real-world problem solving. After all, the way we organize data has a lot of impact on performance and usability. In fact, most top companies require a strong understanding of data structures. These skills demonstrate that you know how to manage your data effectively. Anyone looking to crack the coding interview will need to master data structures.</em></p><h3>JAVASCRIPT DATA STRUCTURES</h3><h3>BINARY SEARCH TREE:</h3><p><em>When we think of a binary search tree, the three things we should think of are:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/0*k3UofamdZSdzfZWF.jpeg" /></figure><ul><li><strong><em>Root: </em></strong><em>This is the very top node of a tree structure and does not have a parent.</em></li><li><strong><em>Parent: </em></strong><em>It is a child of a node but also the parent of a node.</em></li><li><strong><em>Child: </em></strong><em>This node is the child of a node and does not necessarily have a child.</em></li></ul><p><em>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 then the child on the right.</em></p><p><em>The core class for a tree would look like:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/0*gGk9gxxWc6sXtuC_.png" /></figure><p><em>We’ll also create a Node class to represent each of out nodes.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/0*iWz3toOCHjd51h8n.png" /></figure><p><em>Let’s implement the add method. I have commented the code very well, but if you find it confusing, just remember that all we are doing from our root and chekong the left and right of each node.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/0*sEOOx5Axa5JPg8Ec.png" /></figure><p><em>Let;s test our new add method like so:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/0*bbEPN4CTzERn8fQx.png" /></figure><h3>STACK</h3><p><em>This is quite similar to the queue, and you may have heard of the call stack before, which is what JavaScript uses to handle events.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*sPQ__6CgLNJ3RYhp.jpeg" /></figure><p><em>when you have a stack, the last item you pushed on the stack will be the first one removed. This is referred to as last-in, first-out (LIFO). The back button in web browsers is a good example: each page you view is added to the stack, and when you click back, the current page (the last one added) is popped from the stack.</em></p><p><em>That is enough theory. Let’s get into some code</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/0*XVwOHjwd1gIRfnTL.png" /></figure><p><em>I’ve commented the above code, so hopefully you are with me up to this point. The first method we will implement is the push method.</em></p><p><em>So let’s think about what we need this method to do:</em></p><ul><li><em>We need to accept a value</em></li><li><em>We then need to add that value to the top of our stack</em></li><li><em>We also should track the length of our stack so we know our stack’s index</em></li></ul><p><em>It would be great if you could try this yourself first, but if not, the complete push method implementation is below:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/0*M9sE0Fm2fC91bTs7.png" /></figure><p><em>I bet it was easier than you thought. I think with a lot of these structures, they sound more complicated than they actually are.</em></p><p><em>Now let’s get to the pop method. The goal with the pop method is to remove the last value that was added to our stack and then return that value. Try this yourself first if you can, otherwise just continue on to see the solution:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/0*l2va1cQU1J-5Y3Nt.png" /></figure><p><em>The last thing we need to do is the peek function, which looks at the last item in the stack. This is the easiest function: we simply return the last value. Implementation is:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/0*2gxlZr9qjR3PFC0l.png" /></figure><h3>QUEUE</h3><p><em>The key difference between the stack and the queue is that the queue is first-in, first-out (FIFO). There have been a few comments on this article asking why not use an array here, so as a contrast to the above, we will use an array for this data structure.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*Miru6Eyy8kNQThZi" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/278/0*gRpb9XPeaxbYeMEA.png" /></figure><p><em>he two big actions are enqueue and dequeue. We add to the back and remove from the front. Let’s get into implementing a queue to get a better understanding. I had previously used an object here, but I have updated it now to use an array. For the stack data structure, you can also do this approach.</em></p><p><em>The core structure of our code will look like this:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/0*6A0JlCnqhoT9pCw-.png" /></figure><p><em>let’s first implement our enqueue method. Its purpose is to add an item to the back of our queue.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/0*WpdBVcvGX6QPlzO9.png" /></figure><p><em>This is quite a simple method that adds a value to the end of our queue, but you may be a little confused by</em></p><p><em>this.queue[this.length + this.head] = value;</em></p><p><em>Let’s say our queue looked like this</em><em>{14 : &#39;randomVal&#39;}. When adding to this, we want our next key to be </em><em>15, so it would be length(1) + head(14), which gives us </em><em>15.</em></p><p><em>The next method to implement is the dequeue method:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/0*qvuQ3pRcqhhDVy0y.png" /></figure><p><em>The final method to implement is the peek method, which is an easy one:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/0*SrL9Tfgi2Hso8pKj.png" /></figure><h3>LINKED LIST</h3><p><em>This is more complicated than our structures above, but together, we can figure it out.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*33QetJ5Pl-wMP4_A" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/0*PdhGWjIzxrLfR4Fc.png" /></figure><p><em>The first question you might ask is why we would use a linked list. A linked list is mostly used for languages that do not have dynamic sizing arrays. Linked lists organize items sequentially, with each item pointing to the next item.</em></p><p><em>The first thing we are going to create is a Node class.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/0*syD-BMzV5fJeDGYZ.png" /></figure><p><em>The above represents each node in our list.</em></p><p><em>With a class for our Node, the next class we need is our LinkedList.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*s4KJdQqK3MMUxEPS.png" /></figure><p><em>So as we explained above, our LinkedList as a head, which is first set to null (you could add an arg to your constructor to set this if you wanted). We also track the size of our linked list.</em></p><p><em>The first method we are going to implement is insert; this will add a node to our linked list</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/0*bcQn2eTrCxqNamS6.png" /></figure><p><em>I have commented the code above to make it easier to understand, but all we are doing is adding a node to the end of the linked list. We can find the end of our linked list by finding the node that has a next value of null.</em></p><p><em>The next method we are going to implement is removeAt. This method will remove a node at an index.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/0*HZpp2yWft3PY5yV4.png" /></figure><p><em>So the method above will remove a node at a specific index. It does this by updating the next value to point at the next node in the list until we reach the index. This means that no node will be pointing at the node at the index, so it will be removed from our list.</em></p><p><em>The final (easiest) method left to do is clearList.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/0*XrYIyd7OhfwL59Fo.png" /></figure><h3>HASH TABLE</h3><p><em>A hash table is a data structure that implements an associative array, which means it maps keys to values. A JavaScript object is a hash table, as it stores key-value pairs.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*CDszZkBGYANta4G8" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/0*a6bvxZtjSCcsybSo.png" /></figure><p><em>With the hashing function covered, it’s time to talk about how we would implement a hash table.<br>The three operations we will discuss are insert , get , and, finally, remove.</em></p><p><em>The core code to implement a hash table is as follows:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/0*cxJCz4RcuDTYFutB.png" /></figure><p><em>let’s tackle our first method, which is insert The code to insert into a hash table is as follows.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/0*weDZ9PPBxz-BJ0nv.png" /></figure><p><em>So if we were to call the insert method like so:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/0*rG4qFF_7LMLocc2-.png" /></figure><p><em>Now how would we remove from a hash table?</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/0*81hlTTAJB5R6_Nlk.png" /></figure><p><em>The final method we will implement is the get method. This is the same as the remove method, but this time, we return the pair rather than delete it.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/0*aMc8dLTVau0TUMW7.png" /></figure><h3>ALGORITHMS IN JAVASCRIPT</h3><h3>FACTORIAL</h3><p><em>The factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. Such as</em></p><p><em>4! = 4 * 3 * 2 * 1 = 24</em></p><p><em>For example:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/0*AvJNRoISKGALSO7t.png" /></figure><h3>FACTORIAL RECURSIVE</h3><p><em>We can find the factorial of a number using recursion. If you’re having trouble to understand the recursive function then try to think about stack. When a function call is placed the function call is placed on the stack and then the other function calls are placed one top of another. Try to draw the call stack on a note book then may be it will be easier to understand.</em></p><p><em>For Example:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/0*tfZtyDjTZg0hgftl.png" /></figure><h3>FIBONACCI SERIES</h3><p><em>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:</em></p><p><em>[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]</em></p><p><em>For Example:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/0*ZnUR8b14VIMz104g.png" /></figure><h3>LINEAR SEARCH</h3><p><em>In computer science, 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.</em></p><p><em>For Example:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/0*jLXlACZArb0eqQTx.png" /></figure><h3>BINARY SEARCH</h3><p><em>In computer science, binary search, also known as half-interval search, logarithmic search, or binary chop, is a search algorithm that finds the position of a target value within a sorted array. Binary search compares the target value to the middle element of the array; if they are unequal, the half in which the target cannot lie is eliminated and the search continues on the remaining half until it is successful. If the search ends with the remaining half being empty, the target is not in the array.</em></p><p><em>For Example:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/0*zNhZBA5pztH8qXSX.png" /></figure><h3>BUBBLE SORT</h3><p><em>Bubble sort, sometimes referred to as sinking 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.</em></p><p><em>For Example:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/0*3KkiHDSiFG6D77D5.png" /></figure><h3>SELECTION SORT</h3><p><em>Selection sort is a sorting algorithm, specifically an in-place comparison sort. It has O(n2) time complexity, making it inefficient on large lists, and generally performs worse than the similar insertion sort. 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.</em></p><p><em>For Example:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/0*zBNNnfggGWZPM3e9.png" /></figure><h3>INSERTION SORT</h3><p><em>Insertion sort is a simple sorting algorithm that 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.</em></p><p><em>For Example:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/0*WrnMD54iisjzUrOR.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15871fb5e942" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5 USEFUL ALGORITHMS IN JAVASCRIPT]]></title>
            <link>https://medium.com/@mahmud886/5-useful-algorithms-in-javascript-3b14ace585b7?source=rss-8e6ba8805fe7------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b14ace585b7</guid>
            <category><![CDATA[sorting-algorithms]]></category>
            <category><![CDATA[fibonacci]]></category>
            <category><![CDATA[datastrucutre]]></category>
            <category><![CDATA[javascript-algorithms]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Iqbal Mahmud]]></dc:creator>
            <pubDate>Sat, 09 May 2020 14:22:51 GMT</pubDate>
            <atom:updated>2020-05-09T14:22:51.621Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s_c0v9IOuXiPSRbcecZ6Yw.png" /></figure><h3><em>FACTORIAL</em></h3><p><em>The factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. Such as</em></p><p><em>4! = 4 * 3 * 2 * 1 = 24</em></p><p><em>For example:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*Qlt89S8mJd7q_r1GSP0Lrw.png" /><figcaption>FACTORIAL</figcaption></figure><h3><em>FACTORIAL RECURSIVE</em></h3><p><em>We can find the factorial of a number using recursion. If you’re having trouble to understand the recursive function then try to think about stack. When a function call is placed the function call is placed on the stack and then the other function calls are placed one top of another. Try to draw the call stack on a note book then may be it will be easier to understand.</em></p><p><em>For Example:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*4RerPMcmz1_in3qRqDmuCg.png" /><figcaption>FACTORIAL RECURSIVE</figcaption></figure><h3><em>FIBONACCI SERIES</em></h3><p><em>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:</em></p><p><em>[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]</em></p><p><em>For Example:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*QUVqbqxskCqow1F6eCS6_w.png" /><figcaption>FIBONACCI SERIES</figcaption></figure><h3><em>LINEAR SEARCH</em></h3><p><em>In computer science, 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.</em></p><p><em>For Example:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*rjXKjKACaW21J7_jSfIG-A.png" /><figcaption>LINEAR SEARCH</figcaption></figure><h3><em>BINARY SEARCH</em></h3><p><em>In computer science, binary search, also known as half-interval search, logarithmic search, or binary chop, is a search algorithm that finds the position of a target value within a sorted array. Binary search compares the target value to the middle element of the array; if they are unequal, the half in which the target cannot lie is eliminated and the search continues on the remaining half until it is successful. If the search ends with the remaining half being empty, the target is not in the array.</em></p><p><em>For Example:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*1NymAzuopZNXddr8BpnQJQ.png" /><figcaption>BINARY SEARCH</figcaption></figure><h3><em>BUBBLE SORT</em></h3><p><em>Bubble sort, sometimes referred to as sinking 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.</em></p><p><em>For Example:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*68N6askHEN4PHqHJl2o2ZA.png" /><figcaption>BUBBLE SORT</figcaption></figure><h3><em>SELECTION SORT</em></h3><p><em>Selection sort is a sorting algorithm, specifically an in-place comparison sort. It has O(n2) time complexity, making it inefficient on large lists, and generally performs worse than the similar insertion sort. 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.</em></p><p><em>For Example:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*ALyiFwTIiODyCQQsq3yIrQ.png" /><figcaption>SELECTION SORT</figcaption></figure><h3><em>INSERTION SORT</em></h3><p><em>Insertion sort is a simple sorting algorithm that 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.</em></p><p><em>For Example:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*oWr2lBHHuj6YwaEvAwRqEg.png" /><figcaption>INSERTION SORT</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b14ace585b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TOP 5 MAIN DATA STRUCTURES IN JAVASCRIPT]]></title>
            <link>https://medium.com/@mahmud886/top-5-main-data-structures-in-javascript-b4ea8a169a38?source=rss-8e6ba8805fe7------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4ea8a169a38</guid>
            <dc:creator><![CDATA[Iqbal Mahmud]]></dc:creator>
            <pubDate>Fri, 08 May 2020 16:17:14 GMT</pubDate>
            <atom:updated>2020-05-08T16:17:14.909Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/332/1*rEkqx2eFFYO07BO0S_7GnA.jpeg" /></figure><h3><strong>WHAT ARE DATA STRUCTURES?</strong></h3><p><em>Data structures, at a high level, are techniques for storing and organizing data that make it easier to modify, navigate, and access. Data structures determine how data is collected, the functions we can use to access it, and the relationships between data. Data structures are used in almost all areas of computer science and programming, from operating systems to basic vanilla code to artificial intelligence.</em></p><p><em>Data structures enable us to:</em></p><ul><li><em>Manage and utilize large datasets</em></li><li><em>Search for particular data from a database</em></li><li><em>Design algorithms that are tailored towards particular programs</em></li><li><em>Handle multiple requests from users at once</em></li><li><em>Simplify and speed up data processing</em></li></ul><p><em>Data structures are vital for efficient, real-world problem solving. After all, the way we organize data has a lot of impact on performance and usability. In fact, most top companies require a strong understanding of data structures. These skills demonstrate that you know how to manage your data effectively. Anyone looking to crack the coding interview will need to master data structures.</em></p><h3>JAVASCRIPT DATA STRUCTURES</h3><h3>BINARY SEARCH TREE:</h3><p><em>When we think of a binary search tree, the three things we should think of are:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*M1wVV2FrTRQrjFdh--oQOw.jpeg" /></figure><ul><li><strong><em>Root: </em></strong><em>This is the very top node of a tree structure and does not have a parent.</em></li><li><strong><em>Parent: </em></strong><em>It is a child of a node but also the parent of a node.</em></li><li><strong><em>Child: </em></strong><em>This node is the child of a node and does not necessarily have a child.</em></li></ul><p><em>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 then the child on the right.</em></p><p><em>The core class for a tree would look like:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*M80kTsODreVVDaeALoF_Tw.png" /></figure><p><em>We’ll also create a Node class to represent each of out nodes.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*veqBYPokk0oaAU4jyZjerQ.png" /></figure><p><em>Let’s implement the add method. I have commented the code very well, but if you find it confusing, just remember that all we are doing from our root and chekong the left and right of each node.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*GHkxMdMmhkhLq0V3nT6_PQ.png" /></figure><p><em>Let;s test our new add method like so:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*lthNqwJNEzBN3nHdxZunTA.png" /></figure><h3><em>STACK</em></h3><p><em>This is quite similar to the queue, and you may have heard of the call stack before, which is what JavaScript uses to handle events.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*k1lPem8ubXVyCdEERAvDsw.jpeg" /></figure><p><em>when you have a stack, the last item you pushed on the stack will be the first one removed. This is referred to as last-in, first-out (LIFO). The back button in web browsers is a good example: each page you view is added to the stack, and when you click back, the current page (the last one added) is popped from the stack.</em></p><p><em>That is enough theory. Let’s get into some code:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/1*73fJDSdKXWPyQaGCAti4jw.png" /></figure><p><em>I’ve commented the above code, so hopefully you are with me up to this point. The first method we will implement is the push method.</em></p><p><em>So let’s think about what we need this method to do:</em></p><ul><li><em>We need to accept a value</em></li><li><em>We then need to add that value to the top of our stack</em></li><li><em>We also should track the length of our stack so we know our stack’s index</em></li></ul><p><em>It would be great if you could try this yourself first, but if not, the complete push method implementation is below:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*IcShj120-XbK9mIGP8uq_A.png" /></figure><p><em>I bet it was easier than you thought. I think with a lot of these structures, they sound more complicated than they actually are.</em></p><p><em>Now let’s get to the pop method. The goal with the pop method is to remove the last value that was added to our stack and then return that value. Try this yourself first if you can, otherwise just continue on to see the solution:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*R84mOaoePjrNu8dUmwku5g.png" /></figure><p><em>The last thing we need to do is the peek function, which looks at the last item in the stack. This is the easiest function: we simply return the last value. Implementation is:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*wBrtSIa8ggswFW7QVBVvpA.png" /></figure><h3>QUEUE</h3><p><em>The key difference between the stack and the queue is that the queue is first-in, first-out (FIFO). There have been a few comments on this article asking why not use an array here, so as a contrast to the above, we will use an array for this data structure.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/278/1*Ums2BbO0eH6tWPVqnNyfpg.png" /></figure><p><em>he two big actions are enqueue and dequeue. We add to the back and remove from the front. Let’s get into implementing a queue to get a better understanding. I had previously used an object here, but I have updated it now to use an array. For the stack data structure, you can also do this approach.</em></p><p><em>The core structure of our code will look like this:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*PmehMCAROtjzqu5-s-cUyw.png" /></figure><p><em>let’s first implement our enqueue method. Its purpose is to add an item to the back of our queue.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*4YKBXB0_zyZPlaj1C-7RWA.png" /></figure><p><em>This is quite a simple method that adds a value to the end of our queue, but you may be a little confused by</em></p><p><em>this.queue[this.length + this.head] = value;</em></p><p><em>Let’s say our queue looked like this</em><em>{14 : &#39;randomVal&#39;}. When adding to this, we want our next key to be </em><em>15, so it would be length(1) + head(14), which gives us </em><em>15.</em></p><p><em>The next method to implement is the dequeue method:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*TdXlOOzt9D8xe31PTgIPrw.png" /></figure><p><em>The final method to implement is the peek method, which is an easy one:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*KjxU8uhSk2AGhGUUowvUiw.png" /></figure><h3>LINKED LIST</h3><p><em>This is more complicated than our structures above, but together, we can figure it out.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*tnzxVLZyHnZnBsXPOJZCPg.png" /></figure><p><em>The first question you might ask is why we would use a linked list. A linked list is mostly used for languages that do not have dynamic sizing arrays. Linked lists organize items sequentially, with each item pointing to the next item.</em></p><p><em>The first thing we are going to create is a Node class.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*GnFqp7nmV39WWz-MuZwr3w.png" /></figure><p><em>The above represents each node in our list.</em></p><p><em>With a class for our Node, the next class we need is our LinkedList.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*Fwc1TVd8NGjH8Xx3y45JRA.png" /></figure><p><em>So as we explained above, our LinkedList as a head, which is first set to null (you could add an arg to your constructor to set this if you wanted). We also track the size of our linked list.</em></p><p><em>The first method we are going to implement is insert; this will add a node to our linked list</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*H8oPqIocpkt_gVxr9HLvoQ.png" /></figure><p><em>I have commented the code above to make it easier to understand, but all we are doing is adding a node to the end of the linked list. We can find the end of our linked list by finding the node that has a next value of null.</em></p><p><em>The next method we are going to implement is removeAt. This method will remove a node at an index.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*J6U7kN6YeiGpBO-77qIT8g.png" /></figure><p><em>So the method above will remove a node at a specific index. It does this by updating the next value to point at the next node in the list until we reach the index. This means that no node will be pointing at the node at the index, so it will be removed from our list.</em></p><p><em>The final (easiest) method left to do is clearList.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*xyFsiE2p5CyQICsqwtC_GQ.png" /></figure><h3>HASH TABLE</h3><p><em>A hash table is a data structure that implements an associative array, which means it maps keys to values. A JavaScript object is a hash table, as it stores key-value pairs.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*CPz1unGilLS9aKHoXzcAAw.png" /></figure><p><em>With the hashing function covered, it’s time to talk about how we would implement a hash table.<br> The three operations we will discuss are insert , get , and, finally, remove.</em></p><p><em>The core code to implement a hash table is as follows:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*KCmKEJQoGnxC09zRT7hatQ.png" /></figure><p><em>let’s tackle our first method, which is insert The code to insert into a hash table is as follows.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*IDGVSZCR8CzJ6nrTCvC6LA.png" /></figure><p><em>So if we were to call the insert method like so:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*VXb7kADtCngYcME8-LwjgQ.png" /></figure><p><em>Now how would we remove from a hash table?</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*YyS-_ITRdOqWKhGk64UiFg.png" /></figure><p><em>The final method we will implement is the get method. This is the same as the remove method, but this time, we return the pair rather than delete it.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*HLH2mQYL8GMen0Wulhu35w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4ea8a169a38" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>