<?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 Aarti Pandya on Medium]]></title>
        <description><![CDATA[Stories by Aarti Pandya on Medium]]></description>
        <link>https://medium.com/@aarti.pandya46?source=rss-29cb579e211f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*VU-6Eba5s8wFjSJt</url>
            <title>Stories by Aarti Pandya on Medium</title>
            <link>https://medium.com/@aarti.pandya46?source=rss-29cb579e211f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 00:10:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aarti.pandya46/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[Javascript info]]></title>
            <link>https://medium.com/@aarti.pandya46/javascript-info-5ae55abcd7a1?source=rss-29cb579e211f------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ae55abcd7a1</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[cheatsheet]]></category>
            <category><![CDATA[interview]]></category>
            <dc:creator><![CDATA[Aarti Pandya]]></dc:creator>
            <pubDate>Sat, 09 Sep 2023 15:34:55 GMT</pubDate>
            <atom:updated>2023-09-09T15:36:56.604Z</atom:updated>
            <content:encoded><![CDATA[<h3>1) How to add JavaScript to html?</h3><p>There are following 3 ways in which users can add JS</p><ol><li>Embedding code</li><li>Inline code</li><li>External file</li></ol><h4><strong>Embedding code:</strong></h4><p>To add the JavaScript code into the HTML pages, we can use the &lt;script&gt;…..&lt;/script&gt; tag of the HTML that wrap around JavaScript code inside the HTML program.</p><pre>&lt;!DOCTYPE html &gt;  <br>&lt;html&gt;  <br>&lt;head&gt;  <br>&lt;title&gt; page title&lt;/title&gt;  <br>&lt;script&gt;  <br>document.write(&quot;Welcome to Javatpoint&quot;);  <br>&lt;/script&gt;  <br>&lt;/head&gt;  <br>&lt;body&gt;  <br>&lt;p&gt;Inthis example we saw how to add JavaScript in the head section &lt;/p&gt;  <br>&lt;/body&gt;  <br>&lt;/html&gt;</pre><h3>Inline code</h3><p>Generally, this method is used when we have to call a function in the HTML event attributes. There are many cases (or events) in which we have to add JavaScript code directly eg., OnMover event, OnClick, etc.</p><p>Let’s see with the help of an example, how we can add JavaScript directly in the html without using the &lt;script&gt;…. &lt;/script&gt; tag.</p><pre>&lt;!DOCTYPE html &gt;  <br>&lt;html&gt;  <br>&lt;head&gt;  <br>&lt;title&gt; page title&lt;/title&gt;  <br>&lt;/head&gt;  <br>&lt;body&gt;  <br>&lt;p&gt;  <br>&lt;a href=&quot;#&quot; onClick=&quot;alert(&#39;Welcome !&#39;);&quot;&gt;Click Me&lt;/a&gt;  <br>&lt;/p&gt;  <br>&lt;p&gt; in this example we saw how to use inline JavaScript or directly in an HTML tag. &lt;/p&gt;  <br>&lt;/body&gt;  <br>&lt;/html&gt;  </pre><h4>External file</h4><pre>&lt;html&gt;  <br>&lt;head&gt;  <br>&lt;meta charset=&quot;utf-8&quot;&gt;  <br>&lt;title&gt;Including a External JavaScript File&lt;/title&gt;  <br>&lt;/head&gt;  <br>&lt;body&gt;  <br>&lt;form&gt;  <br>&lt;input type=&quot;button&quot; value=&quot;Result&quot; onclick=&quot;display()&quot;/&gt;  <br>&lt;/form&gt;  <br>&lt;script src=&quot;hello.js&quot;&gt;  <br>&lt;/script&gt;  <br>&lt;/body&gt;  <br>&lt;/html&gt;  </pre><p><strong>Hello.js</strong></p><pre>function display() {  <br>  alert(&quot;Hello World!&quot;);  <br>}  </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*IN9AXJ5isdJIyRgIzFbmdA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ae55abcd7a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Javascript Interview Questions]]></title>
            <link>https://medium.com/@aarti.pandya46/khk-8dbc232ec3a?source=rss-29cb579e211f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8dbc232ec3a</guid>
            <dc:creator><![CDATA[Aarti Pandya]]></dc:creator>
            <pubDate>Mon, 03 Jul 2023 12:26:18 GMT</pubDate>
            <atom:updated>2023-07-15T16:57:32.339Z</atom:updated>
            <content:encoded><![CDATA[<h3>What are closures?</h3><p>Closure is a combination of functions bundled together in a lexical scope. The inner function has access to an outer function scope, variables and parameters even after the outer function has returned.</p><pre>function init() {<br>  var name = &quot;Mozilla&quot;; // name is a local variable created by init<br>  function displayName() {<br>    // displayName() is the inner function, that forms the closure<br>    console.log(name); // use variable declared in the parent function<br>  }<br>  displayName();<br>}<br>init();</pre><h3>Difference between regular function vs arrow function?</h3><p>1.Syntax — No implicit return for arrow function</p><p>2. Argument Binding — In regular function, Arguments keywords can be used to access the arguments of which passed to function.</p><pre>function regularFunction(a,b) {<br>console.log(arguments);<br>}<br>regularFunction(1,2)<br>// Arguments[1,2]</pre><pre>const arrowFunction = (a,b) =&gt; {<br>  console.log(arguments);<br>}<br>arrowFunction(1,2);<br>//Reference Error : Arguments is not defined<br><br>//Workaround for arrow function<br>var arrowFunction=(...args){<br>console.log(...args);<br>}<br>arrowFunction(1,2);<br>// 1 2</pre><p>3. this keyword — Normal function depends on how it is being called and arrow function is on where it is being called.</p><p>4. New keyword — Regular functions are constructible, they can be called using the new keyword.</p><pre>function add (x, y) {<br>  console.log(x + y);<br>}<br><br>let sum = new add(2,3);<br>// 5<br><br>let add = (x, y) =&gt; console.log(x + y);<br>const sum = new add(2,4);<br>// TypeError: add is not a constructor</pre><p>5.Function Hoisting — In regular function, function gets hoisting at top.</p><pre>normalFunction();<br>function normalFunction(){<br>  console.log(&quot;Hello&quot;);<br>}</pre><p>In arrow function, function get hoisted where you define. So, if you call the function before initialisation you will get referenceError.</p><pre>arrowFunc();<br>const arrrowFunction=()=&gt;console.log(&quot;Hello&quot;);<br>// ReferenceError: Cannot access &#39;arrowFunc&#39; before initialization</pre><h3>What is Lexical Environment / lexical Scope?</h3><p>The lexical scoping means that inside the inner scope you can access variables of outer scopes.</p><h3>What is currying?</h3><p>Currying in JavaScript transforms a function with multiple arguments into a nested series of functions, each taking a single argument.</p><pre>function sum(a, b, c) {<br>    return a + b + c;<br>}<br>sum(1,2,3); // 6<br><br>function curry(a){<br>  return function(b){<br>    return function(c){<br>      return a+b+c;<br>      }<br>    }<br>  }<br>curry(1)(2)(3);</pre><h3>Difference between Call, Apply and Bind?</h3><p>Call and Apply calls a function, while bind returns a new function.</p><p>Arguments are passed individually on call while apply expects an array of arguments.</p><pre>let participant1 = { <br>  name:&quot;lily&quot;, <br>  battery: 40,<br>  chargeBattery: function(a,b){ <br>    this.battery = this.battery + a + b; <br>  } <br>}<br><br>let participant2 = { <br>  name:&quot;john&quot;, <br>  battery: 30 <br>}<br><br>participant1.chargeBattery.call(participant2, 20, 30) ;<br>participant1.chargeBattery.bind(participant2, 20, 30)();<br>participant1.chargeBattery.apply(participant2, [ 20, 30 ]);<br></pre><h3>What is an Event Loop?</h3><p>An event loop is something that pulls the task of the callback queue / microtask queue and places it onto the execution call stack whenever the call stack becomes empty.</p><h3>Prototype in Javascript?</h3><p>Prototype is mechanism by which javascript object inherit features from another object.</p><pre>const myObject = {<br>  city: &quot;Madrid&quot;,<br>  greet() {<br>    console.log(`Greetings from ${this.city}`);<br>  },<br>};<br><br>myObject.greet(); // Greetings from Madrid</pre><p>This is an object with one data property, city, and one method, greet(). If you type the object&#39;s name <em>followed by a period</em> into the console, like myObject., then the console will pop up a list of all the properties available to this object.</p><pre>__defineGetter__<br>__defineSetter__<br>__lookupGetter__<br>__lookupSetter__<br>__proto__<br>city<br>constructor<br>greet<br>hasOwnProperty<br>isPrototypeOf<br>propertyIsEnumerable<br>toLocaleString<br>toString<br>valueOf</pre><h3>What is higher order functions?</h3><p>It is a function that accepts another function as an argument and even can return the function as a value.</p><p>#Higher order functions A <strong>higher-order</strong> function is a function that does at least one of the following:</p><ul><li>Takes one or more functions as an input</li><li>Outputs a function</li></ul><pre>var animals = [ {name: &#39;Milo&#39;, type: &#39;cat&#39;, eyes: 2}, <br>{name: &#39;Peluza&#39;, type: &#39;cat&#39;, eyes: 2},<br> {name: &#39;Yummy&#39;, type: &#39;cat&#39;, eyes: 2}, <br>{name: &#39;Doggy&#39;, type: &#39;dog&#39;, eyes: 2}, <br>{name: &#39;Sammy&#39;, type: &#39;dog&#39;, eyes: 2} ];<br>// Using map method: Map It iterates over an array and return a new array with the changes you do to it. <br><br>const getAnimals = animals.map(animal =&gt; `${animal.name} is a ${animal.type}`);<br><br>getAnimals = [ <br>&#39;Milo is a cat&#39;, <br>&#39;Peluza is a cat&#39;, <br>&#39;Yummy is a cat&#39;, <br>&#39;Doggy is a dog&#39;, <br>&#39;Sammy is a dog&#39; ]</pre><p>So, map,filter and find are example of Higher Order Functions.</p><h3>What is event delegation?</h3><p>Capturing and bubbling allow us to implement one of the most powerful event handling patterns called <em>event delegation</em>.</p><p>The idea is that if we have a lot of elements handled in a similar way, then instead of assigning a handler to each of them — we put a single handler on their common ancestor.</p><p>In the handler we get event.target to see where the event actually happened and handle it.</p><pre>&lt;table&gt;<br>  &lt;tr&gt;<br>    &lt;th colspan=&quot;3&quot;&gt;&lt;em&gt;Bagua&lt;/em&gt; Chart: Direction, Element, Color, Meaning&lt;/th&gt;<br>  &lt;/tr&gt;<br>  &lt;tr&gt;<br>    &lt;td class=&quot;nw&quot;&gt;&lt;strong&gt;Northwest&lt;/strong&gt;&lt;br&gt;Metal&lt;br&gt;Silver&lt;br&gt;Elders&lt;/td&gt;<br>    &lt;td class=&quot;n&quot;&gt;...&lt;/td&gt;<br>    &lt;td class=&quot;ne&quot;&gt;...&lt;/td&gt;<br>  &lt;/tr&gt;<br>  &lt;tr&gt;...2 more lines of this kind...&lt;/tr&gt;<br>  &lt;tr&gt;...2 more lines of this kind...&lt;/tr&gt;<br>&lt;/table</pre><p><strong>Our task is to highlight a cell </strong><strong>&lt;td&gt; on click.</strong></p><p>Instead of assign an onclick handler to each &lt;td&gt; (can be many) – we’ll setup the “catch-all” handler on &lt;table&gt; element.</p><p>It will use event.target to get the clicked element and highlight it.</p><pre>table.onclick = function(event) {<br>  let td = event.target.closest(&#39;td&#39;); // (1)<br>  if (!td) return; // (2)<br>  if (!table.contains(td)) return; // (3)<br>  highlight(td); // (4)<br>};</pre><h3>What is promises?</h3><p>Promise is an object that produce a single value.</p><p>With promises, we can postpone the execution of a code block until an asynchronous operation is completed.</p><p>This way, other operations can keep running without interruption.</p><p><strong>Promises have three states:</strong></p><p>1. Pending: the initial state of the promise</p><p>2. Fulfilled: the specified operation was completed.</p><p>3. Rejected: the operation did not complete</p><pre>let prom = new Promise((res, rej) =&gt; { <br>    console.log(&#39;synchronously executed&#39;); <br>    if (Math.random() &gt; 0.5) <br>    res(&#39;Success&#39;); <br>    else <br>    rej(&#39;Error&#39;); <br>})<br><br>prom.then((val) =&gt; { console.log(&#39;asynchronously executed: &#39; + val); })<br>.catch((err) =&gt; { console.log(&#39;asynchronously executed: &#39; + err); })<br>.finally(() =&gt; { console.log(&#39;promise done executing&#39;); }); <br><br>console.log(&#39;last log&#39;);</pre><h3>Difference between null and undefined?</h3><p>null is a special keyword that indicates an absence of value.</p><p>undefined property indicates that a variable has not been assigned a value including null too.</p><h3>Difference between asynchronous and synchronous?</h3><p>Synchronous are blocking and asynchronous are not.</p><p>Synchronous complete running the current code before executing the next code are executed while asynchronous continue on the next code without completing the current code.</p><h3>Different Data types in JS?</h3><p>Number, bigint, string , Boolean , Object , undefined , null and symbol.</p><h3>Primitive Data types?</h3><p>Primitive data type is data that is not an object and has no methods and is immutable,can not be altered.</p><p>There are 7 primitive data types: string, number, bigint, boolean, undefined, symbol, and null.</p><p>All primitive data type interact by value.</p><h3>What is Hoisting?</h3><p>In the creation phase of the code, memory space is set up for variables and functions. This is called hoisting.</p><p>Hoisting is when the JavaScript interpreter moves all variable and function declarations to the top of the current scope.</p><p>It’s important to keep in mind that only the actual declarations are hoisted, and that assignments are left where they are.</p><p>Only variables declared with var are hoisted , not the let &amp; const.</p><p>While functions are hoisted not the arrow functions.</p><pre><br>console.log(x);<br>var x=12;<br>//undefined<br><br>console.log(y);<br>const y=9;<br>//Error<br><br>console.log(z);<br>let z=90;<br>//Error<br><br>sum(2,5);<br>function sum(a,b){<br>  console.log(a+b);<br>}<br>//7</pre><h3>Difference between arrow function and normal function?</h3><p>Normal function depends on how the this keyword is called or on which object is it called.</p><p>Arrow function only depends on where the function is called.</p><p>We can make an new instance of a function( constructor ) using new keyword for normal functions.</p><p>With arrow function there is no constructer involved.</p><h3>Difference between Object.freeze() and Object.seal()?</h3><p>Object.freeze() — Read only</p><p>Object.seal() — Read and Update only</p><h3>ES6 Features</h3><p>1. Let and const</p><p>2. Arrow functions</p><p>3. Template Literals</p><p>4. Default parameters</p><p>5. Object / Array destructure</p><p>6. Spread</p><h3>What is Async/Await?</h3><p>The newest way to write asynchronous code in JavaScript.</p><p>It is non blocking (just like promises and callbacks).</p><p>Async/Await was created to simplify the process of working with and writing chained promises.</p><p>Async functions return a Promise. If the function throws an error, the Promise will be rejected. If the function returns a value, the Promise will be resolved.</p><pre>const getResponse = async () =&gt; {<br>     try {<br>          const response = await axios.get(&#39;url&#39;)<br>     } catch(err) {<br>          console.log(&#39;err&#39;)<br>     }<br>}</pre><h3>Explain event bubbling and how one may prevent it.</h3><p><strong>Event bubbling</strong> is the concept in which an event triggers at the deepest possible element, and triggers on parent elements in nesting order.</p><p>As a result, when clicking on a child element one may exhibit the handler of the parent activating.</p><p>One way to prevent event bubbling is using event.stopPropagation() or event.cancelBubble on IE &lt; 9.</p><h3>What is Coercion?</h3><p>JavaScript is a <strong>dynamically typed language</strong>: we don’t specify what types certain variables are. Values canautomatically be converted into another type without you knowing, which is called <em>implicit typecoercion</em>.</p><p><strong>Coercion</strong> is converting from one type into another.</p><p>ex- sum(1, “2”) → 12</p><h3>Implement a general Debouncing function.</h3><pre>const debounce = (func, time) =&gt; { <br>let timer; <br>return () =&gt; { <br>  clearTimeout(timer); <br>  timer = setTimeout(() =&gt; { func(); }, time); <br> }; <br>};<br><br>const debounceTest = () =&gt; { console.log(&quot;testing debounce&quot;); };<br>console.log(debounce(debounceTest, 1000))</pre><h3>Implement a general Memoization function.</h3><h3>Implement your own Array.prototype.flat()</h3><p>So here we will implement out own flat() and call it a myflat()</p><pre>const arr = [[1,3,4,6],[4,5,2,8],[7,3,8,3,9]]; <br>Array.prototype.myflat = () =&gt; { <br>    let newArr = []; <br>    for( let i = 0 ; i &lt; arr.length; i++){ <br>      for (let j = 0 ; j &lt; arr[i].length ; j++){ <br>        newArr.push(arr[i][j]) <br>      }<br>    }<br>    return newArr;<br>}<br>console.log(arr.myflat());</pre><h3>Implement your own throttle</h3><h3><strong>What is the drawback of declaring methods directly in JavaScript objects?</strong></h3><p>One of the drawbacks of declaring methods directly in JavaScript objects is that they are very memory inefficient. When you do that, a new copy of the method is created for each instance of an object. Here’s an example:</p><pre>var Employee = function (name, company, salary) {<br>this.name = name || &quot;&quot;;<br>this.company = company || &quot;&quot;;<br>this.salary = salary || 5000;<br><br>// We can create a method like this<br>this.formatSalary = function () {<br>  return &quot;$ &quot; + this.salary;<br>}<br><br>// Alternatively we can add the method to Employee&#39;s prototype:<br>Employee.prototype.formatSalary2 = function() {<br>return &quot;$ &quot; + this.salary;<br>}<br><br>//creating objects<br>var emp1 = new Employee(&#39;Yuri Garagin&#39;, &#39;Company 1&#39;, 1000000);<br>var emp2 = new Employee(&#39;Dinesh Gupta&#39;, &#39;Company 2&#39;, 1039999);<br>var emp3 = new Employee(&#39;Erich Fromm&#39;, &#39;Company 3&#39;, 1299483);</pre><p>In this case each instance variable</p><p>emp1, emp2, emp3 has its own copy of the formatSalary method.</p><p>However the formatSalary2 will only be added once to Employee.prototype.</p><h3><strong>What are Service Workers and when can you use them?</strong></h3><p>It’s a technology that allows your web application to use cached resources first, and provide default experience offline, before getting more data from the network later.</p><p>This principle is commonly known as Offline First.</p><p>Service Workers actively use promises. A Service Worker has to be installed,activated and then it can react on fetch, push and sync events.</p><h3><strong>What is the difference between a method and a function in javascript?</strong></h3><p>A function is a set of instructions or procedures to perform a specific task, and a method is a set of instructions that are associated with an object.</p><pre>// Function statement<br>function myFunc() {<br>// Do some stuff;<br>}<br>myFunc();<br>// Methods<br>var obj1 = {<br>  attribute: &quot;xyz&quot;,<br>  myMethod: function () { // Method<br>    console.log(this.attribute);<br>  }<br>};<br>//Call the method<br>obj1.myMethod();<br></pre><h3><strong>What are the ways of creating objects in JavaScript ?</strong></h3><p><strong>Creating object with a constructor:</strong></p><pre>// Simple function<br>function vehicle(name,maker,engine){<br> this.name = name;<br> this.maker = maker;<br> this.engine = engine;<br>}<br>// New keyword to create an object<br>let car = new vehicle(&#39;GT&#39;,&#39;BMW&#39;,&#39;1998cc&#39;);<br>// Property accessors<br>console.log(car.name);<br>console.log(car.maker);<br>console.log(car[&#39;engine&#39;]);</pre><p><strong>Using object literals:</strong></p><pre>// Creating js objects with object literal<br>let car = {<br> name : &#39;GT&#39;,<br> maker : &#39;BMW&#39;,<br> engine : &#39;1998cc&#39;<br>};<br>// Property accessor<br>console.log(car.name); //dot notation<br>console.log(car[&#39;maker&#39;]); //bracket notation</pre><p><strong>Creating object with </strong><a href="https://www.geeksforgeeks.org/object-create-javascript/"><strong>Object.create()</strong></a><strong> method:</strong></p><pre>const coder = {<br> isStudying : false,<br> printIntroduction : function(){<br>  console.log(`My name is ${this.name}. Am I studying?: ${this.isStudying}`);<br> }<br>};<br>const me = Object.create(coder);<br>me.name = &#39;Mukul&#39;;<br>me.isStudying = true;<br>me.printIntroduction();</pre><p><strong>Using es6 classes</strong></p><pre>// Using es6 classes<br>class Vehicle {<br>  constructor(name, maker, engine) {<br>   this.name = name;<br>   this.maker = maker;<br>   this.engine = engine;<br>  }<br>}<br>let car1 = new Vehicle(&#39;GT&#39;, &#39;BMW&#39;, &#39;1998cc&#39;);<br>console.log(car1.name); //GT</pre><h3><strong>Write a function called deepClone which takes an object and creates a object copy of it.</strong></h3><pre>function deepClone(object)<br>{ <br>  var newObject = {}; <br>  for(var key in object){ <br>    if(typeof object[key] === &#39;object&#39; &amp;&amp; object[key] !== null )<br>      newObject[key] = deepClone(object[key]); <br>    else<br>      newObject[key] = object[key];<br>  }<br>  return newObject; <br>}<br>//sample object <br>var personalDetail = { <br>name : &#39;Nishant&#39;, <br>address : { <br>location: &#39;xyz&#39;, <br>zip : &#39;123456&#39;, <br>phoneNumber :{ <br>  homePhone: 8797912345,<br>  workPhone : 1234509876 <br>  } <br>} <br>}<br>//calling deepClone function <br>deepClone(personalDetail);</pre><h3><strong>Write code for merge two JavaScript Object dynamically.</strong></h3><p>Lets say we have 2 objects.</p><pre>var person = { name : &#39;Sandip&#39;, age : 26 }<br>var address = { <br>  addressLine1 : &#39;Some Location x&#39;,<br>  addressLine2 : &#39;Some Location y&#39;,<br>}<br><br>function merge(toObj, fromObj) { <br>if (typeof toObj === &#39;object&#39; &amp;&amp; typeof fromObj === &#39;object&#39;) { <br>  for (var pro in fromObj) { <br>  // Assign only own properties not inherited properties <br>    if (fromObj.hasOwnProperty(pro))<br>      toObj[pro] = fromObj[pro];<br>  } <br>}<br>else{ <br>  throw &quot;Merge function can apply only on object&quot;; } <br>}<br>//calling function <br>merge(person, address)</pre><h3><strong>What is generator in JS?</strong></h3><p>Generators are functions which can be exited and later re-entered. Their context (variable bindings) will be saved across re-entrances.</p><p>Generator functions are written using the function* syntax.</p><p>When called initially, generator functions do not execute any of their code, instead returning a type of iterator called a Generator.</p><p>When a value is consumed by calling the generator’s next method, the Generator function executes until it encounters the yield keyword.</p><p>The function can be called as many times as desired and returns a new Generator each time, however each Generator may only be iterated once.</p><pre>function* makeRangeIterator(start = 0, end = Infinity, step = 1) {<br>  let iterationCount = 0;<br>  for (let i = start; i &lt; end; i += step) {<br>  iterationCount++;<br>  yield i;<br>  }<br>  return iterationCount;<br>}</pre><h3><strong>When should we use generators in ES6?</strong></h3><p>To put it simple, generator has two features:</p><p>one can choose to jump out of a function and let outer code to determine when to jump back into the function.</p><p>the control of asynchronous call can be done outside of your code</p><p>The most important feature in generators — we can get the next value in only when we really need it, not all the values at once. And in some situations it can be very convenient.</p><h3><strong>Difference between .map() and .forEach()? which one to choose over other?</strong></h3><p><strong>forEach</strong></p><p>Iterates through the elements in an array.</p><p>Executes a callback for each element.</p><p>Does not return a value.</p><p><strong>map</strong></p><p>Iterates through the elements in an array.</p><p>“Maps” each element to a new element by calling the function on each element, creating a new array as a result.</p><p>The main difference between .forEach and .map() is that .map() returns a new array. If you need the result, but do not wish to mutate the original array, .map() is the clear choice. If you simply need to iterate over an array, forEach is a fine choice.</p><p><strong>What is the Temporal Dead Zone in ES6?</strong></p><p>In ES6 let and const are hoisted (like var , class and function ), but there is a period between entering scope and being declared where they cannot be accessed. <strong>This period is the temporal dead zone (TDZ).</strong></p><pre>console.log(aLet) // would throw ReferenceError <br>let aLet; <br>console.log(aLet); // undefined <br>aLet = 10; <br>console.log(aLet); // 10</pre><h3>splice vs. slice in javascript</h3><h3>slice:</h3><p>It is used to cut out elements from an array.</p><pre>array.slice(start, end)</pre><ul><li>start denotes the index at which the array starts slicing.</li><li>end denotes the index at which the array stops slicing.</li></ul><p>The returned value of the slice method is an array of the values found between start and end <strong>excluding the value at </strong><strong>end</strong>.</p><pre>let arr = [&quot;educative&quot;, 4, [1,3], {type: &quot;animal&quot;}];<br>let slicedValues = arr.slice(1,3);<br>console.log(arr);<br>console.log(slicedValues);<br><br>//output<br>[ &#39;educative&#39;, 4, [ 1, 3 ], { type: &#39;animal&#39; } ]<br>[ 4, [ 1, 3 ] ]</pre><h3>splice:</h3><p>The splice() method adds and/or removes array elements.</p><p>The splice() method modifies the original array.</p><pre>array.splice(start, deleteCount, newElem1, newElem2, ..., newElemN;</pre><ul><li>start denotes the index from which the method will start its operation on the array.</li><li>deleteCount denotes the number of values to be deleted from the start. If the value is 0, nothing will be deleted.</li><li>newElem1 to newElemN denote the values that would be added after the start.</li></ul><pre>let arr = [&quot;educative&quot;,4,[1,3],{type: &quot;animal&quot;}];<br>let returnedArr = arr.splice(2,1,{name: &quot;educative&quot;});<br>console.log(arr);<br>console.log(returnedArr);<br><br>//output<br>[ &#39;educative&#39;, 4, { name: &#39;educative&#39; }, { type: &#39;animal&#39; } ]<br>[ [ 1, 3 ] ]</pre><h3><strong>Difference Between Promise and Async/Await.</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*eWfNdtr2kQ4na3_TLRNPrQ.png" /></figure><h3>What is shallow copy and deep copy in JavaScript ?</h3><p><strong>Shallow Copy: </strong>When a reference variable is copied into a new reference variable using the assignment operation, a shallow copy of the referenced object is created.</p><pre>let employee = {<br> eid: &quot;E102&quot;,<br> ename: &quot;Jack&quot;,<br> eaddress: &quot;New York&quot;,<br> salary: 50000<br>}<br><br>console.log(&quot;Employee=&gt; &quot;, employee);<br>let newEmployee = employee; // Shallow copy<br>console.log(&quot;New Employee=&gt; &quot;, newEmployee);<br><br>console.log(&quot;---------After modification----------&quot;);<br>newEmployee.ename = &quot;Beck&quot;;<br>console.log(&quot;Employee=&gt; &quot;, employee);<br>console.log(&quot;New Employee=&gt; &quot;, newEmployee);<br>// Name of the employee as well as<br>// newEmployee is changed.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*EFhIvu2hqhYdy2JHhmAsrA.png" /></figure><p><strong>Deep Copy: Unlike the shallow copy, deep copy</strong> makes a copy of all the members of the old object, allocates a separate memory location for the new object, and then assigns the copied members to the new object.</p><pre>let employee = {<br> eid: &quot;E102&quot;,<br> ename: &quot;Jack&quot;,<br> eaddress: &quot;New York&quot;,<br> salary: 50000<br>}<br>console.log(&quot;=========Deep Copy========&quot;);<br>let newEmployee = JSON.parse(JSON.stringify(employee));<br>console.log(&quot;Employee=&gt; &quot;, employee);<br>console.log(&quot;New Employee=&gt; &quot;, newEmployee);<br>console.log(&quot;---------After modification---------&quot;);<br>newEmployee.ename = &quot;Beck&quot;;<br>newEmployee.salary = 70000;<br>console.log(&quot;Employee=&gt; &quot;, employee);<br>console.log(&quot;New Employee=&gt; &quot;, newEmployee);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*c7Ein8KccCrvTgCgMlUqLg.png" /></figure><h3>Strict mode in Javascript?</h3><p>JavaScript strict mode enables a secure environment for JavaScript development.</p><p>In this mode, it does not allow codes with bad syntaxes and throws an error.</p><p>The statement “use strict”; instructs the browser to use the Strict mode, which is a reduced and safer feature set of JavaScript.</p><ul><li>Using strict mode, don’t allow to use a variable without declaring it.</li><li>Deleting a variable (or object) and a function is not allowed.</li><li>The string “eval” cannot be used as a variable.</li><li>The string “arguments” cannot be used as a variable.</li></ul><h3>Difference between let,var and const.</h3><pre>function foobar(){<br>    if(true){<br>        var x=9;let y=1;const z=3;<br>        console.log(x);console.log(y);console.log(z);<br>    }<br>    console.log(x);<br>    console.log(y); // Error<br>    console.log(z); // Error<br>}<br>foobar();<br><br>// var hasfunction scope<br>// let,const has block scope</pre><ul><li>In the var tab, when you will run the code, you will see an error as a is not defined because var variables are only accessible in the function scope.</li><li>In the let tab, when you run the code, you will see an error as i is not defined because let variables are only accessible within the block they are declared.</li><li>In the const tab, when you run the code, you will see that x was defined under the block was accessible, but when you try to access x outside that block, you will get an error.</li></ul><h3>Spread and rest operator</h3><pre>const student1={<br>    name:&quot;aarti&quot;,<br>    age:32,<br>    city:&quot;pune&quot;<br>};<br><br>//spread<br>const student2={<br>  ...student1,<br>  name:&quot;angel&quot;,<br>}<br>console.log(student1);<br>console.log(student2);<br><br>//rest<br>const {name,...rest}=student1;<br>console.log(name);<br>console.log(rest);<br><br>//output<br>{ name: &#39;aarti&#39;, age: 32, city: &#39;pune&#39; }<br>{ name: &#39;angel&#39;, age: 32, city: &#39;pune&#39; }<br>aarti<br>{ age: 32, city: &#39;pune&#39; }</pre><h3>Throttling in Javascript</h3><p>Throttling is also used to rate-limit the function call. Throttling will fire the function call only once in 1000ms(the limit which we have provided), no matter how many times the user fires the function call.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*gX_j4Vcb8ILFZk5YK-SYPQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*J-jJTCUjtq1wff0PFa-mwQ.jpeg" /></figure><h3>Types of loops</h3><ul><li>for loop</li><li>for (..in) loop</li><li>for (..of) loop</li><li>while loop</li><li>do-while loop</li></ul><p><strong>for (..in) loop:</strong> The JavaScript for (..in) statement loops through the enumerable properties of an object.</p><p><strong>for (..of) loop:</strong> This for (..of) statement lets you loop over the data structures that are iterable such as Arrays, Strings, Maps, Node Lists, and more.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8dbc232ec3a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Slice() and Splice() method in Javascript]]></title>
            <link>https://medium.com/@aarti.pandya46/slice-and-splice-method-in-javascript-8f841dfd16ff?source=rss-29cb579e211f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f841dfd16ff</guid>
            <dc:creator><![CDATA[Aarti Pandya]]></dc:creator>
            <pubDate>Mon, 03 Jul 2023 08:23:24 GMT</pubDate>
            <atom:updated>2023-07-03T08:29:22.403Z</atom:updated>
            <content:encoded><![CDATA[<h3>JavaScript Array slice()</h3><h3>Description</h3><p>The slice() method returns selected elements in an array, as a new array.</p><p>It selects from a given <em>start</em>, up to a (not inclusive) given <em>end</em>.</p><p>It does not change the original array.</p><h3>Syntax</h3><p><em>array</em>.slice(<em>start</em>,<em> end</em>)</p><p><strong><em>Parameters</em></strong></p><p><strong><em>start</em></strong></p><p>Optional.</p><p>Start position.Default is 0.<br>Negative numbers select from the end of the array.</p><p><strong><em>end</em></strong></p><p>Optional.<br>End position.Default is last element.<br>Negative numbers select from the end of the array.</p><h3>Return Value</h3><p>A new array containing the selected elements.</p><h3>Examples</h3><p>const fruits = [“Banana”, “Orange”, “Lemon”, “Apple”, “Mango”];<br>const citrus = fruits.slice(1, 3);</p><p>// Orange,Lemon</p><p>const fruits = [“Banana”, “Orange”, “Lemon”, “Apple”, “Mango”];<br>const myBest = fruits.slice(-3, -1);</p><p><strong>// </strong>Lemon,Apple</p><h3>JavaScript Array splice()</h3><h3>Description</h3><p>It adds and/or removes array elements.</p><p>It overwrites the original array.</p><h3>Syntax</h3><p><em>array</em>.splice(<em>index</em>,<em> howmany</em>,<em> item1</em>, …..,<em> itemX</em>)</p><h3>Parameters</h3><p><em>index</em></p><p>Required.<br>The position to add/remove items.<br>Negative value defines the position from the end of the array.</p><p><em>howmany</em></p><p>Optional.<br>Number of items to be removed.</p><p><em>item1</em>, …, <em>itemX</em></p><p>Optional.<br>New elements(s) to be added.</p><h3>Return Value</h3><p>An array containing the removed items (if any).</p><h3>Examples</h3><p>At position 2, add 2 elements:</p><p>const fruits = [“Banana”, “Orange”, “Apple”, “Mango”];</p><p>fruits.splice(2, 0, “Lemon”, “Kiwi”);</p><p>// Banana,Orange,Lemon,Kiwi,Apple,Mango</p><p>At position 2, remove 2 items:</p><p>const fruits = [“Banana”, “Orange”, “Apple”, “Mango”, “Kiwi”];<br>fruits.splice(2, 2);</p><p>// Banana,Orange,Kiwi</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f841dfd16ff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSS Grid Layout Module]]></title>
            <link>https://towardsdev.com/css-grids-made-easy-100-8e966b199dd7?source=rss-29cb579e211f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e966b199dd7</guid>
            <category><![CDATA[grid-layout]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[grid]]></category>
            <category><![CDATA[html]]></category>
            <dc:creator><![CDATA[Aarti Pandya]]></dc:creator>
            <pubDate>Fri, 17 Jun 2022 07:55:28 GMT</pubDate>
            <atom:updated>2022-06-17T12:06:34.194Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>CSS grid</strong> creates responsive two dimensional web design layouts more easily and consistently across browsers.</p><p>In the past, there have been other methods for controlling web page layout methods, such as <strong><em>tables</em></strong>, <strong><em>floats</em></strong>, and more recently, <strong><em>flexbox</em></strong>.</p><p>CSS grid can create more robust and flexible layouts than the previous options like CSS floats.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0yFkwkQriOHYg0Z3xI-yJw.jpeg" /></figure><h3>Grid</h3><p>A grid layout consists of a parent element, with one or more child elements.</p><h3>Creating a Grid Container</h3><p>To make an HTML element behave as a grid container, you have to set the display property to grid.</p><h3>CSS Grid Properties</h3><p><strong>grid-template-columns</strong> : Specifies the size of the columns, and how many columns in a grid layout.</p><p><strong>grid-template-rows</strong> : Specifies the size of the rows in a grid layout.</p><p><strong>gap</strong> : A shorthand property for the row-gap and the column-gap properties.</p><p><strong>grid-column-start</strong>: Specifies where to start the grid item.</p><p><strong>grid-column-end</strong> : Specifies where to end the grid item.</p><p><strong>grid-row-start</strong> Specifies where to start the grid item.</p><p><strong>grid-row-end</strong> Specifies where to end the grid item.</p><h3>A Grid Layout Example</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*zSbYVhO27J-kuv4-Pej0Mw.jpeg" /></figure><p>Here is our HTML:</p><pre>&lt;div class=&quot;app-layout&quot;&gt;<br>  &lt;div class=&quot;tweets&quot;&gt;Tweets&lt;/div&gt;<br>  &lt;div class=&quot;replies&quot;&gt;Replies&lt;/div&gt;<br>  &lt;div class=&quot;search&quot;&gt;Search&lt;/div&gt;<br>  &lt;div class=&quot;messages&quot;&gt;Messages&lt;/div&gt;<br>&lt;/div&gt;</pre><p>Then we will apply some CSS to the .app-layout container element:</p><pre>.app-layout {<br>  display: grid;      /*grid-template-columns: 25% 25% 25% 25%;*/<br>  grid-template-columns:1fr 1fr 1fr 1fr;<br>  grid-template-rows: 100vh;<br>}</pre><p><strong><em>View a live demo here : </em></strong><a href="https://codepen.io/apandya/pen/JjpzzNy">https://codepen.io/apandya/pen/JjpzzNy</a></p><p>Here is the explanation of what we’ve done in the previous CSS:</p><ol><li>Set the display property to grid.</li><li>Divide the container element into four columns, each column is 1fr (one fraction) of the free space within the grid container.</li><li>Create one row and set the height to be 100vh (full viewport height).</li></ol><p>As you can see, the Grid Layout Module adds a new value to the display property which is <strong><em>grid</em></strong>. The grid value is responsible for setting the .app-layout element to be a grid container. This property is required to start using Grid Layout.</p><p>The<strong><em> grid-template-columns</em></strong> property specifies the width of each grid column within the Grid, and in our case it divides the <strong><em>.app-layout </em></strong>container to four columns; each one is<strong><em> 1fr (25%) </em></strong>of the available space.</p><p>The <strong><em>grid-template-rows</em></strong> specifies the height of each grid row, and in our example we only created one row at <strong><em>100vh</em></strong>.</p><h3>Position Items by Using a Line Number</h3><p>You can refer to an exact line number in a grid by using the properties <strong><em>grid-column-start</em></strong> and<strong><em> grid-column-end</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*BmAJ5ONIIh2yAYRjgyTGNA.png" /></figure><p>Looking at the previous example, this is how the browser positions the elements by default for us:</p><pre>.<strong>tweets   </strong>{<br>  grid-column-start: 1;<br>  grid-column-end: 2;<br>  grid-row: 1;<br>}</pre><pre>.replies  {<br>  grid-column-start: 2;<br>  grid-column-end: 3;<br>  grid-row: 1;<br>}</pre><pre>.search   {<br>  grid-column-start: 3;<br>  grid-column-end: 4;<br>  grid-row: 1;<br>}</pre><pre>.messages {<br>  grid-column-start: 4;<br>  grid-column-end: 5;<br>  grid-row: 1;<br>}</pre><p>Looking at the code for the .tweet column, this is what each of the three lines in the CSS does:</p><ol><li>Position the child element starting from the first vertical line on the left.</li><li>End the element’s position at the second vertical line.</li><li>Position the element inside the whole row.</li></ol><p>You can also use <strong><em>span (n) </em></strong>where <strong><em>n </em></strong>specifies no. of rows or columns.</p><h4>Example : Place a grid item at column line 1, and let it end on column line 3:</h4><pre>.item1 {<br><strong>  </strong>grid-column-start: 1;      /*grid-column-start: span 2;*/<br>  grid-column-end: 3;<br>}</pre><h4>Example : Place a grid item at row line 1, and let it end on row line 3</h4><pre>.item1 {<br><strong>  </strong>grid-row-start: 1;      /* grid-row-start: span 2;*/<br>  grid-row-end: 3;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pkjj6Ij1mW2dnG6GZ5ezIA.png" /><figcaption>output</figcaption></figure><p>Here is our HTML for this.</p><pre><strong>&lt;</strong>div class=&quot;grid-container&quot;&gt;<br>     &lt;div class=&quot;grid-item-1&quot;&gt;Header&lt;/div&gt;<br>     &lt;div class=&quot;grid-item-2&quot;&gt;Menu&lt;/div&gt;<br>     &lt;div class=&quot;grid-item-3&quot;&gt;Main&lt;/div&gt;<br>     &lt;div class=&quot;grid-item-4&quot;&gt;Right&lt;/div&gt;<br>     &lt;div class=&quot;grid-item-5&quot;&gt;Footer&lt;/div&gt;<br>&lt;/div&gt;</pre><p>And we would use the following CSS:</p><pre>.grid-container {<br>    display: grid;<br>    grid-template-columns: auto auto auto auto;<br>    gap: 10px;<br>    background-color: #2196f3;<br>    padding: 10px;<br>}</pre><pre>.grid-item-2 {<br>    grid-row-start: span 2;<br>}</pre><pre>.grid-item-3 {<br>    grid-column-start: span 2;<br>}</pre><pre>.grid-item-5 {<br>    grid-column-start: span 3;<br>}</pre><p>View a Live demo here <a href="https://codepen.io/apandya/pen/xxYBBEq">https://codepen.io/apandya/pen/xxYBBEq</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e966b199dd7" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/css-grids-made-easy-100-8e966b199dd7">CSS Grid Layout Module</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[StrictMode in React]]></title>
            <link>https://medium.com/@aarti.pandya46/strict-mode-f011918f94e5?source=rss-29cb579e211f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f011918f94e5</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactive-programming]]></category>
            <dc:creator><![CDATA[Aarti Pandya]]></dc:creator>
            <pubDate>Wed, 01 Jun 2022 13:25:13 GMT</pubDate>
            <atom:updated>2022-06-02T05:11:00.229Z</atom:updated>
            <content:encoded><![CDATA[<p>StrictMode does not render any visible UI but it is a tool for highlighting potential problems in an application.</p><figure><img alt="Warnings in development mode." src="https://cdn-images-1.medium.com/max/489/1*SToxtYVuJDN868E6nkQOYw.png" /></figure><p>It activates additional checks and warnings for its descendants.</p><p>You can enable strict mode for any part of your application like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*W3WmnvPnd4ObqanPUYdFgQ.png" /></figure><p>StrictMode currently helps with:</p><ul><li><strong>Identifying components with unsafe lifecycles</strong></li><li><strong>Warning about legacy string ref API usage</strong></li><li><strong>Warning about deprecated findDOMNode usage</strong></li><li><strong>Detecting legacy context API</strong></li></ul><h3>Identifying unsafe lifecycles</h3><p>Certain legacy lifecycle methods are unsafe for use in async React applications. However, if your application uses third party libraries, it can be difficult to ensure that these lifecycles aren’t being used.</p><p>Fortunately, strict mode can help with this!</p><p>When strict mode is enabled, React compiles a list of all class components using the unsafe lifecycles, and logs a warning message with information about these components, like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*nSRp1HuUS0TTAbVveXuGZQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/0*8vj79446ixI93396.png" /></figure><h3>Warning about legacy string ref API usage</h3><p>Previously, React provided two ways for managing refs: the legacy string ref API and the callback API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*L9IqdINStEzIBLQNs29qnw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*G8OmhlK2Vpz6g7CBvJf-7A.png" /></figure><p>React 16.3 added a third option that offers the convenience of a string ref without any of the downsides.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*tivX9PymFYqyHqPdvgJnFA.png" /></figure><p>Since object refs were largely added as a replacement for string refs, strict mode now warns about usage of string refs.</p><h3>Warning about deprecated findDOMNode usage</h3><p>In class-based components, the FindDOMNode() method is used to return DOM of the given element.</p><p>findDOMNode can also be used on class components but this was breaking abstraction levels by allowing a parent to demand that certain children were rendered.</p><p>For Ex: In <strong>Semantic UI React</strong>, this is a known issue, most of their components are still using findDOMNode(). This will be fixed in the <a href="https://github.com/Semantic-Org/Semantic-UI-React/pull/4233">Semantic UI React v3</a> where all these components will be updated to use React.forwardRef().</p><p>You can instead make this explicit by passing a ref to your custom component and pass that along to the DOM using <a href="https://reactjs.org/docs/forwarding-refs.html#forwarding-refs-to-dom-components">r</a>ef forwarding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*VOxcrjMgr8OdH-ViIDkjMg.png" /></figure><h3>Detecting legacy context API</h3><p>The legacy context API is error-prone, and will be removed in a future major version.</p><p>It works for all 16.x releases but will show this warning message in strict mode:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/0*0v4TWHqsyxpzvUtH.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f011918f94e5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tricky JavaScript Snippets]]></title>
            <link>https://medium.com/@aarti.pandya46/javascript-code-snippets-you-might-fail-to-answer-during-interview-ec66920a994d?source=rss-29cb579e211f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec66920a994d</guid>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[javascript-development]]></category>
            <dc:creator><![CDATA[Aarti Pandya]]></dc:creator>
            <pubDate>Wed, 18 May 2022 04:33:07 GMT</pubDate>
            <atom:updated>2022-06-06T07:35:00.074Z</atom:updated>
            <content:encoded><![CDATA[<p>(1) setTimeout</p><pre>console.log(&quot;one&quot;);</pre><pre>setTimeout(()=&gt;console.log(&quot;two&quot;),0);</pre><pre>Promise.resolve().then(()=&gt;{<br>    console.log(&quot;three&quot;);<br>});</pre><pre>console.log(&quot;four&quot;)</pre><p>output</p><pre>one<br>four<br>three<br>two</pre><p>(2) Center a &lt;div&gt; on a page vertically and horizontally</p><pre>&lt;div&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum accumsan tellus purus, et mollis nulla consectetur ac. Quisque id elit at diam convallis venenatis eget sed justo.&lt;/div&gt;</pre><pre>div {<br> border:1px solid red<br>  padding: 15px;<br>  position: absolute;<br>  top: 50%;<br>  left: 50%;<br>  transform: translate(-50%,-50%);<br>}</pre><p>(3) Higher order functions</p><pre>function noisy(f) {<br>  return (...args) =&gt; {<br>    console.log(&quot;calling with&quot;, args);<br>    let result = f(...args);<br>    console.log(&quot;called with&quot;, args, &quot;, returned&quot;, result);<br>    return result;<br>  };<br>}<br>noisy(Math.min)(3, 2, 1);</pre><p>output</p><pre>calling with [3, 2, 1]<br>called with [3, 2, 1] , returned 1</pre><p>(4) Hoisting in javascript</p><pre>function fun(){<br>setTimeout(()=&gt;{<br>     console.log(i);<br>     var i=1;<br>},1000);<br>}<br>fun();</pre><p>output</p><pre>undefined</pre><p>Magic!<br>Variables are partially hoisted while functions are hoisted fully.</p><pre>console.log(i);<br>console.log(sayHello);<br>sayHello();</pre><pre>var i=1;</pre><pre>function sayHello(){<br>    console.log(&#39;hello&#39;);<br>}</pre><p>output</p><pre>undefined</pre><pre>ƒ sayHello(){<br>    console.log(&#39;hello&#39;);<br>}</pre><pre>hello</pre><blockquote>Now try with <em>Let</em></blockquote><p>Variables declared with const and let are available in temporary dead zone and not accessible but variables declared with <strong><em>var (ie : global scope) </em></strong>are hoisted and accessible.</p><pre>//let example<br>console.log(age);<br>console.log(name);   // ReferencError: name is not defined</pre><pre>let name=&#39;Michel&#39;;<br>var age=23;</pre><p>output</p><pre>undefined<br><em>// ReferencError: name is not defined</em></pre><p><strong>(6)The Event Loop</strong></p><pre>console.log(&quot;before&quot;);</pre><pre>fetch(&#39;<a href="https://jsonplaceholder.typicode.com/todos/1&#39;">https://jsonplaceholder.typicode.com/todos/1&#39;</a>)<br>  .then(response =&gt; response.json())<br>  .then(json =&gt; console.log(json))<br>  <br>console.log(&quot;after&quot;)</pre><p>output</p><pre>before</pre><pre>after</pre><pre>{ completed: false, id: 1, title: “delectus aut autem”, userId: 1 }</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec66920a994d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript: call(), apply() and bind()]]></title>
            <link>https://medium.com/@aarti.pandya46/javascript-call-apply-and-bind-aae8186a9856?source=rss-29cb579e211f------2</link>
            <guid isPermaLink="false">https://medium.com/p/aae8186a9856</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Aarti Pandya]]></dc:creator>
            <pubDate>Thu, 12 May 2022 05:47:20 GMT</pubDate>
            <atom:updated>2022-05-15T11:53:27.856Z</atom:updated>
            <content:encoded><![CDATA[<p>With the call(),apply() and bind() methods, an object can borrow a method from another object.</p><p><strong>Borrowing a method</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*g2SxuWgos6EaoR0y8rlL0A.png" /></figure><pre>With the call() method, an object can borrow a method from another object.</pre><p>The call() method is a predefined JavaScript method.</p><blockquote>The call() method calls a function with a given this value and arguments provided individually.</blockquote><blockquote>Here, <strong><em>this</em></strong> refers to the object for which we are calling the method.</blockquote><pre>const person = {<br>  fullName: function(city) {<br>    return this.firstName + &quot; &quot; + this.lastName + &quot;,&quot; + city;<br>  }<br>}<br><br>const person1 = {<br>  firstName:&quot;Mike&quot;,<br>  lastName: &quot;Ross&quot;<br>}<br><br>person.fullName.call(person1, &quot;New York&quot;);</pre><p>output</p><pre>Mike Ross,New York</pre><pre>With the apply() method, an object can borrow a method from another object.</pre><p>The apply() method calls a function with a given this value, and arguments provided as an array (or an <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Indexed_collections#working_with_array-like_objects">array-like object</a>).</p><p><em>Here</em><strong><em>,this</em></strong> refers to the object for which we are calling the method.</p><p>The apply() method is similar to the call() method except <br>The call() method takes arguments <strong>separately</strong>.<br>The apply() method takes arguments as an <strong>array</strong>.</p><pre>const person = {<br>  fullName: function(city) {<br>    return this.firstName + &quot; &quot; + this.lastName + &quot;,&quot; + city;<br>  }<br>}<br><br>const person1 = {<br>  firstName:&quot;MIke&quot;,<br>  lastName: &quot;Ross&quot;<br>}<br><br>person.fullName.apply(person1, [&quot;New York&quot;]);</pre><p>output</p><pre>Mike Ross,New York</pre><pre>With the bind() method, an object can borrow a method from another object.</pre><p>The bind() method creates a new function that, when called, has its this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.</p><blockquote>Here, <strong><em>this</em></strong> refers to the object for which we are calling the method.</blockquote><p>The bind() method returns a new function, when invoked, has its sets to a specific value.</p><pre>const person = {<br>  fullName: function(city) {<br>    return this.firstName + &quot; &quot; + this.lastName + &quot;,&quot; + city;<br>  }<br>}<br><br>const person1 = {<br>  firstName:&quot;Mike&quot;,<br>  lastName: &quot;Ross&quot;<br>}<br><br>let getFullName=person.fullName.bind(person1, &quot;New York&quot;);<br>getFullName();</pre><p>output</p><pre>Mike Ross,New York</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aae8186a9856" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>