<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Adarsh Pandya</title>
    <description>The latest articles on DEV Community by Adarsh Pandya (@whoadarshpandya).</description>
    <link>https://dev.to/whoadarshpandya</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F424116%2F7c4c1404-b5e5-4c2b-b74b-db9adf5daf49.jpeg</url>
      <title>DEV Community: Adarsh Pandya</title>
      <link>https://dev.to/whoadarshpandya</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/whoadarshpandya"/>
    <language>en</language>
    <item>
      <title>Enough JavaScript to get you Started : #19 IIFE✨</title>
      <dc:creator>Adarsh Pandya</dc:creator>
      <pubDate>Fri, 29 Jan 2021 08:04:30 +0000</pubDate>
      <link>https://dev.to/whoadarshpandya/enough-javascript-to-get-you-started-19-iife-3j2k</link>
      <guid>https://dev.to/whoadarshpandya/enough-javascript-to-get-you-started-19-iife-3j2k</guid>
      <description>&lt;h3&gt;
  
  
  IIFE ✨
&lt;/h3&gt;

&lt;p&gt;👉 IIFE or &lt;code&gt;immediately invoked functions as expressions&lt;/code&gt; simply refers to a function which runs as soon as it is defined.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;👉 Which means if you have to write a function which runs in beginning of your web app , you can use IIFE.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;👉 in early days if we want to do something like this we need to define a function and call it... &lt;br&gt;&lt;/p&gt;

&lt;p&gt;👉 but with IIFE design pattern the syntax and the code makes much more sense. &lt;br&gt;&lt;/p&gt;

&lt;p&gt;👉 IIFE takes 2 parentheses , one is meant for defining a anonymous function and another is meant to call the anonymous function.&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;&lt;code&gt;Syntax&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(
  // anonymous function
  function () {
    //function body
})();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;br&gt;
👉 We'll create one IIFE which will greet user as soon as he/she comes to our website 😀 &lt;br&gt;&lt;br&gt;
👉 &lt;strong&gt;&lt;code&gt;Example : the old way&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greet () {
    alert('hello user ! how are you?');
}

greet();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;👉 &lt;strong&gt;&lt;code&gt;Example : the new way&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(function(){
    alert('hello user ! how are you?');
})();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 &lt;strong&gt;&lt;code&gt;Example : Arrow functions as IIFE&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;( () =&amp;gt; {
      alert('hello user ! how are you?');
})();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let me know in comment section if you have any doubt or feedback. it's always worth to give time to the thriving developer community :) &lt;br&gt;
&lt;br&gt;
Keep Coding ❤
&lt;/p&gt;

&lt;h4&gt;
  
  
  Hey , Let' Connect👋
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://twitter.com/codarsh"&gt;Twitter&lt;/a&gt; /&lt;br&gt;
 &lt;a href="https://github.com/WhoAdarshPandya/"&gt;Github&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>100daysofcode</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Enough JavaScript to get you Started : #18 Optional chaining and nullish coalescing</title>
      <dc:creator>Adarsh Pandya</dc:creator>
      <pubDate>Tue, 26 Jan 2021 06:52:14 +0000</pubDate>
      <link>https://dev.to/whoadarshpandya/enough-javascript-to-get-you-started-18-optional-chaining-and-nullish-coalescing-1839</link>
      <guid>https://dev.to/whoadarshpandya/enough-javascript-to-get-you-started-18-optional-chaining-and-nullish-coalescing-1839</guid>
      <description>&lt;h3&gt;
  
  
  Optional Chanining &lt;code&gt;?.&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;👉 According to  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining"&gt;MDN&lt;/a&gt; The optional chaining operator (?.) permits reading the value of a property located deep within a chain of connected objects without having to expressly validate that each reference in the chain is valid.&lt;/p&gt;

&lt;p&gt;👉 To put it more simply , let's take an example where you have to fetch data to client side from the backend, so data come in form of &lt;strong&gt;JSON&lt;/strong&gt; &lt;code&gt;{javaScript object notation}&lt;/code&gt; but sometimes due to error or wrong credentials &lt;code&gt;null&lt;/code&gt; will be returned...&lt;/p&gt;

&lt;p&gt;👉 So to make our code more error proof we've to do something like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// ignore next line if you don't know , assume we're fetching data from server
let data = async fetch('https://randomuser.me/api')
let name ="";

// now data may or may not come so we've to check it like 
if(data)
{
   if(data.user !== null)
   {
       if(data.user.name !== "" or data.user.name !== null)
       {
              let name = data.user.name;
       }
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 This code is safer but also more verbose. Our data isn’t even that deeply nested; a more complicated object might have many more levels to check.&lt;/p&gt;

&lt;p&gt;👉 Using Optional chaining &lt;code&gt;?.&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let data = async fetch('https://randomuser.me/api')

// using optional chaining
let name = data?.user?.name;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 As we can see optional chaning &lt;code&gt;(?.)&lt;/code&gt; helps us to write minimal and optimized code. &lt;br&gt;&lt;/p&gt;

&lt;p&gt;👉 To make it even more simpler , optional chaining looks that if data has user object or it is null. if it finds user object it goes one level down and check for name whether it's available or not. if it finds user null it won't go one level down which results in &lt;code&gt;Cannot read property 'user' of undefined&lt;/code&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
👉 Unlike manual testing with our code , it won't give us error , rather it returns undefined.&lt;/p&gt;



&lt;h3&gt;
  
  
  Nullish coalescing &lt;code&gt;??&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;👉 According to  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator"&gt;MDN&lt;/a&gt; the nullish coalescing operator (??) is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined, and otherwise returns its left-hand side operand.&lt;/p&gt;

&lt;p&gt;👉 in simple words &lt;code&gt;??&lt;/code&gt; will return right hand side operand if the left hand value is nullish&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can't we do that with &lt;code&gt;||&lt;/code&gt; 🤔?&lt;/strong&gt; &lt;br&gt;&lt;br&gt;
👉 The answer is yes definitely but this might not work in some falsy values like &lt;code&gt;""&lt;/code&gt; or &lt;code&gt;NaN&lt;/code&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;👉&lt;em&gt;a scenario where &lt;code&gt;||&lt;/code&gt; won't work...&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cartItems = 0;
let msg = "";

let qty = cartItems  || 10;
let message = msg|| "hi!";
console.log(qty);     // 10 and not 0
console.log(message); // "hi!" and not ""
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉the values like &lt;code&gt;""&lt;/code&gt; , &lt;code&gt;0&lt;/code&gt; , &lt;code&gt;NaN&lt;/code&gt; are considered to be falsy value, so logically &lt;code&gt;||&lt;/code&gt; is doing it's job , but not serving our purpose ! hence we need to use Nullish coalescing(&lt;code&gt;??&lt;/code&gt;)&lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let cartItems = 0;
let msg = "";

let qty = cartItems  ?? 10;
let message = msg ?? "hi!";
console.log(qty);     // 0 ✔
console.log(message); // "" ✔
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let me know in comment section if you have any doubt or feedback. it's always worth to give time to the thriving developer community :) &lt;br&gt;
&lt;br&gt;
Keep Coding ❤
&lt;/p&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
Hey Let's Connect 👋&lt;br&gt;
&lt;a href="https://twitter.com/codarsh"&gt;Twitter&lt;/a&gt; / &lt;a href="https://github.com/whoadarshpandya"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>Enough JavaScript to get you Started : #17 rest,spread and destructuring</title>
      <dc:creator>Adarsh Pandya</dc:creator>
      <pubDate>Sun, 24 Jan 2021 06:44:42 +0000</pubDate>
      <link>https://dev.to/whoadarshpandya/enough-javascript-to-get-you-started-17-rest-spread-and-destructuring-422k</link>
      <guid>https://dev.to/whoadarshpandya/enough-javascript-to-get-you-started-17-rest-spread-and-destructuring-422k</guid>
      <description>&lt;h3&gt;
  
  
  rest and spread operator (&lt;code&gt;...&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;👉 rest and spread operators came out with release of ECMA6&lt;br&gt;
&lt;br&gt;&lt;br&gt;
👉&lt;code&gt;...&lt;/code&gt; can be used as rest as well as spread operator&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  rest
&lt;/h3&gt;

&lt;p&gt;👉 collects all remaining params into a single array &lt;br&gt;&lt;/p&gt;

&lt;p&gt;👉 &lt;em&gt;Problem statement : &lt;code&gt;write a function which can perform sum of N numbers&lt;/code&gt;&lt;/em&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;👉Code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sum = (n1,n2,n3) =&amp;gt; {
       return n1+n2+n3;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 this solution works for only 3 numbers but as per the definition we've to add N numbers &lt;br&gt;&lt;/p&gt;

&lt;p&gt;👉 now the problem is we don't know how many params are going to passed maybe 3 maybe 5 maybe 100? &lt;br&gt;&lt;/p&gt;

&lt;p&gt;👉 we can't write 100 function for 100 numbers&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Solution : use rest operator&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;👉 rest operator (&lt;code&gt;...&lt;/code&gt;) collects all the actual values passed and then combines them into one array , so we can pass n number of params without having to write separate functions for each of problems&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;&lt;code&gt;Example&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sumOfN = (...elements) =&amp;gt; {
     let total = 0;
     // remember rest passes array as arguement
     // we'll loop through each element and add them into total.
     for(i=0;i&amp;lt;elements.length;i++)
     {
             // += is short hand for 'total = total + elements[i]`
             total+=elements[i]; // will add items from array one by one
     }
     return total;
}

// let's check
sumOfN(1); // ✔ returns 1
sumOfN(1,2); // ✔ returns 3
sumOfN(1,2,3); // ✔ returns 6
sumOfN(1,2,3,4); // ✔ returns 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 according to ECMA standards the param which will use rest operator need to be last in parameters&lt;/p&gt;

&lt;p&gt;👉 &lt;code&gt;Example&lt;/code&gt; : &lt;code&gt;sumOfN(someOtherVar,...elements)&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Spread operator
&lt;/h3&gt;

&lt;p&gt;👉 Spread operator have similar (&lt;code&gt;...&lt;/code&gt;) expression as rest operator but it works in different context&lt;br&gt;
&lt;br&gt;&lt;br&gt;
👉Spread operators allows us to expand elements without having to write loops explicitly &lt;br&gt;&lt;br&gt;
&lt;strong&gt;Let's understand it through example&lt;/strong&gt;&lt;br&gt;
👉 &lt;em&gt;Problem statement : &lt;code&gt;create a program which can merge two arrays&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;👉 The old way :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr1=[1,2,3];
let arr2 = [4,5,6];
let mergedArray = [];
for(let item of arr1)
{      
       // push method is used to push elements into array at last index
       mergedArray.push(item);
}
for(let item of arr2)
{      
       mergedArray.push(item);
}

console.log(mergedArray);
// will print [1,2,3,4,5,6]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 The new way with spread operator :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr1 = [1,2,3];
let arr2 = [4,5,6];

// '...arr1' will unpack 1,2,3 into mergedArray
// '...arr2' will unpack 4,5,6 into mergedArray
let mergedArray = [...arr1,...arr2];

console.log(mergedArray);
// will print [1,2,3,4,5,6]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Spread makes it easy to work with day to day array operations &lt;/p&gt;



&lt;h3&gt;
  
  
  Destructuring
&lt;/h3&gt;

&lt;p&gt;👉 Descructuring in JavaScript simply refers to popping out the desired values from Objects and Arrays&lt;/p&gt;

&lt;p&gt;👉 &lt;code&gt;Example : The old way&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const 🐕 = {
       name : "sharron",
       color : "black",
       age : 9
}

// old way to access values
const name = 🐕.name;
const color = 🐕.color;
const age = 🐕.age;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 &lt;code&gt;Example : The new way&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const 🐕 = {
       name : "sharron",
       color : "black",
       age : 9
}

// using destructuring to extract values
const {name,color,age} = 🐕;

console.log(name); // sharron
console.log(color);  // black
console.log(age);    // age

const heros = ['iron man', 'super man', 'spider man'];

const [hero1, hero2, hero3] = heros;
console.log(hero1); // "iron man"
console.log(hero2); // "super man"
console.log(hero3); // "spider man"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let me know in comment section if you have any doubt or feedback. it's always worth to give time to the thriving developer community :) &lt;br&gt;
&lt;br&gt;
Keep Coding ❤
&lt;/p&gt;

&lt;h4&gt;
  
  
  Hey , Let' Connect👋
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://twitter.com/codarsh"&gt;Twitter&lt;/a&gt; /&lt;br&gt;
 &lt;a href="https://github.com/WhoAdarshPandya/"&gt;Github&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>100daysofcode</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Enough JavaScript to get you Started : #16 var vs let vs const</title>
      <dc:creator>Adarsh Pandya</dc:creator>
      <pubDate>Fri, 22 Jan 2021 06:52:44 +0000</pubDate>
      <link>https://dev.to/whoadarshpandya/enough-javascript-to-get-you-started-16-var-vs-let-vs-const-48f</link>
      <guid>https://dev.to/whoadarshpandya/enough-javascript-to-get-you-started-16-var-vs-let-vs-const-48f</guid>
      <description>&lt;h3&gt;
  
  
  Before we start
&lt;/h3&gt;

&lt;p&gt;👉 Before we start this article i would like to clarify some technical jargons for you &lt;br&gt;&lt;br&gt;
👉 Scope : Scope is nothing but a code block where the variable is accessible for usage &lt;br&gt;&lt;br&gt;
👉 Global Scope : Global Scope means variable is declared globally (not in some condition or function) hence it can be used any where throughout the execution of program &lt;br&gt;&lt;br&gt;
👉 Local/ Functional Scope : this simply means that when we declare a variable on function level or somewhere locally in code block then it's not accessible outside of that particular scope (imagine variables declared in functions , loops ,conditionals...) &lt;br&gt;&lt;br&gt;
👉 Block Scope : Blocks are nothing but piece of code written inside any curly braces {...} [ex. if block , or function's block]&lt;/p&gt;
&lt;h3&gt;
  
  
  Var
&lt;/h3&gt;

&lt;p&gt;👉 Var is the oldest way of declaring variable &lt;br&gt;&lt;br&gt;
👉 Var can be globally and functionally scoped &lt;br&gt;&lt;br&gt;
👉 If we Declare var inside function it becomes functionally scoped if we declare it outside function it becomes globally scoped and is available anywhere in program&lt;br&gt;&lt;br&gt;
👉 can be redeclared or updated&lt;/p&gt;

&lt;p&gt;👉&lt;strong&gt;Example of Scope&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var a = 10; // global variable

function fun()
{
    // functional scoped variable
    var b = 20;
    console.log(a);
    console.log(b);
}
fun();
console.log(a);
console.log(b);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;-&amp;gt; inside function
10 ✔
20 ✔
-&amp;gt; outside function
10 ✔
uncaught reference : b is not defined ❌ 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Notice that functions can access both global and functional variables.&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Example of Re-declaration&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// variables with var can be re-decalred ✔
var a = 10;
var a = 20;
// you won't get any error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 &lt;strong&gt;Example of updatable variables&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// variables with var can be updated ✔
var a =10;
a=20;
// you won't get any error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 &lt;strong&gt;Problems with var&lt;/strong&gt; &lt;br&gt;&lt;br&gt;
👉 Redefining variables won't throw any errors which means it's tricky to remember which variable is already there and which variable is new. &lt;br&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Let
&lt;/h3&gt;

&lt;p&gt;👉 Let is the modern way of declaring variables introduces in ES2015 &lt;br&gt;&lt;br&gt;
👉 Let is now recommended way of declaring variables &lt;br&gt;&lt;br&gt;
👉 Let is &lt;strong&gt;block scoped&lt;/strong&gt; &lt;br&gt;&lt;br&gt;
👉 Let can be updated but not redeclared &lt;br&gt;&lt;/p&gt;

&lt;p&gt;👉&lt;strong&gt;Example of Declaration&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// let can be updated ✔
let a = 30; ✔
a = 40; ✔
// but not redeclared ❌
let b = 40; ✔
let b = 90 ;❌

// error : Identifier 'b' has already been declared
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉&lt;strong&gt;Example of block scope&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let sayHi = "hi";
if(sayHi === "hi")
{
    let newMsg = "how are you?";
   console.log(sayHi); // outputs "hi"
}

console.log(sayHi); ✔
console.log(newMsg); ❌ // 'newMsg is not defined'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;h3&gt;
  
  
  Const
&lt;/h3&gt;

&lt;p&gt;👉 Variables declared with &lt;code&gt;const&lt;/code&gt; remains same throughout the execution &lt;br&gt;&lt;br&gt;
👉 variables declared with &lt;code&gt;const&lt;/code&gt; are not redeclarable or updatable &lt;br&gt;&lt;br&gt;
👉 if &lt;code&gt;const&lt;/code&gt; variables declared outside any block they becomes global scoped , but if they are declared within block they becomes block scoped &lt;br&gt;&lt;br&gt;
👉 values can not be changes or new values can not be assigned to &lt;code&gt;const&lt;/code&gt; variables&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sayHi = "hi";
const sayHi = "hello"; ❌ // will throw error

//and ...

const msg = "buy bread from market";
msg = "new msg here"; ❌ // error:  assignment to constant variable.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 But...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1,2,3];
number[0] = 4; ✔ // works fine

// but...
numbers = [5,6,7]; ❌ // won't work
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 the first case will work because we're within the rules , we're not redeclaring the const variable nor we're updating it. but we're mutating it. 😀&lt;/p&gt;



&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;👉 &lt;strong&gt;var:&lt;/strong&gt; Global/function scoped depending on declaration undefined when accessing a variable before it's declared. can be redeclared and updated.&lt;br&gt;
&lt;br&gt;&lt;br&gt;
👉 &lt;strong&gt;let:&lt;/strong&gt; block scoped. can be updated but we can't redeclare.&lt;br&gt;
&lt;br&gt;&lt;br&gt;
👉&lt;strong&gt;const:&lt;/strong&gt; block scoped. can not be reassigned nor we can redeclare.&lt;/p&gt;

&lt;p&gt;Let me know in comment section if you have any doubt or feedback. it's always worth to give time to the thriving developer community :) &lt;br&gt;
&lt;br&gt;
Keep Coding ❤
&lt;/p&gt;

&lt;h4&gt;
  
  
  Hey , Let' Connect👋
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://twitter.com/codarsh"&gt;Twitter&lt;/a&gt; / &lt;a href="https://github.com/WhoAdarshPandya/"&gt;Github&lt;/a&gt; &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>Enough JavaScript to get you Started : #15 Arrow Functions</title>
      <dc:creator>Adarsh Pandya</dc:creator>
      <pubDate>Thu, 21 Jan 2021 11:53:20 +0000</pubDate>
      <link>https://dev.to/whoadarshpandya/enough-javascript-to-get-you-started-15-arrow-functions-19o6</link>
      <guid>https://dev.to/whoadarshpandya/enough-javascript-to-get-you-started-15-arrow-functions-19o6</guid>
      <description>&lt;h3&gt;
  
  
  Arrow Functions?
&lt;/h3&gt;

&lt;p&gt;👉 Since we've covered Basics of JavaScript , it's now time to move towards slightly advance things 🎉&lt;br&gt;
&lt;br&gt;&lt;br&gt;
👉Arrow Functions are compact alternatives to regular JavaScript functions&lt;br&gt;
&lt;br&gt;&lt;br&gt;
👉Arrow Functions will help you jump into modern JS concepts , and extremely helpful before learning any JS frameworks like React or Angular&lt;/p&gt;
&lt;h3&gt;
  
  
  Have you seen something like this?
&lt;/h3&gt;

&lt;p&gt;👉 Sometimes when our code doesn't work as expected so we go to stack overflow or GitHub for finding solutions.&lt;/p&gt;

&lt;p&gt;👉 Let's say you were getting error in Adding 2 numbers (i know you won't😂, but still)...&lt;/p&gt;

&lt;p&gt;👉 You go to stack overflow and see something like this...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var sum = (a,b) =&amp;gt; {
      return a+b;  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  WTF was that? Language of gods? 🤔
&lt;/h3&gt;

&lt;p&gt;👉 Let's break down this into simple function&lt;br&gt;
&lt;br&gt;&lt;br&gt;
👉 So what's written here basically, is this...&lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function sum(a,b)
{
       return a+b;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Arrow function helps to reduce syntax (often known as syntactic sugar) over vanilla js by ES2016&lt;/p&gt;



&lt;h3&gt;
  
  
  Benefits of Array Functions
&lt;/h3&gt;

&lt;p&gt;👉 Helps to reduce syntax &lt;br&gt;&lt;br&gt;
👉 Arrow syntax automatically binds this to the surrounding code’s context (will be covered later in series 😁)&lt;br&gt;&lt;br&gt;
👉 Implicit Return &lt;br&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  What are Arrow Functions any way?
&lt;/h3&gt;

&lt;p&gt;👉 Arrow function is modern way of writing normal JavaScript function which helps us in writing lesser and more meaningfulfunctions.&lt;br&gt;
&lt;br&gt;&lt;br&gt;
👉 Arrow Functions are also known as &lt;strong&gt;Fat Arrow Functions&lt;/strong&gt; because of the &lt;code&gt;=&amp;gt;&lt;/code&gt; expression in syntax&lt;br&gt;
&lt;br&gt;&lt;br&gt;
👉 &lt;strong&gt;&lt;em&gt;Syntax&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// normal function
var functionName = function (param1,param2) {
      // function body
      // ...
      // ...
}

// arrow function
var functionName = (param1,param2) =&amp;gt; {
       // function body
       // ...
       // ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 in simple terminology ,  we assign an anonymous function to a variable where the name of variable becomes the name of function and can be called by &lt;code&gt;functionName();&lt;/code&gt; . &lt;br&gt;&lt;/p&gt;

&lt;p&gt;👉 Parentheses in arrow function indicates number or params our function will take (in our case there are two , namely &lt;em&gt;param1&lt;/em&gt; and &lt;em&gt;param2&lt;/em&gt;)&lt;br&gt;
&lt;br&gt;&lt;br&gt;
👉 After Arrow (&lt;code&gt;=&amp;gt;&lt;/code&gt;) , the curly braces indicates the start of function body , where we can write whatever we want inside it.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Examples
&lt;/h3&gt;

&lt;p&gt;👉 Writing  a Arrow Function which can return sum of 2 nums&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// sum : name of arrow function
// n1,n2 : params of arrow function
// {...} : body of arrow function

var sum = (n1,n2) =&amp;gt; {
      return n1+n2;
}

// can be called like : 
sum(1,2);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Writing  a Arrow Function which can return cube of given number&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
// arrow function with one param
var cube = num =&amp;gt; {
       return num*num;
}

// can be called like : 
cube(2);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Writing  a Arrow Function which can will ask for user age and checks if he/she is eligible for license&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// arrow function with 0 params
var licenseValidator = () =&amp;gt; {
    var age = +prompt("what's your age ? ");
    if(age &amp;gt; 18)
    {
          console.log("eligilbe")
    } else {
          console.log("not eligible"); 
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Rules for Writing Arrow functions
&lt;/h3&gt;

&lt;p&gt;👉 &lt;code&gt;=&amp;gt;&lt;/code&gt; is compulsory before function body. &lt;br&gt;&lt;br&gt;
👉 we've to pass empty parentheses&lt;code&gt;()&lt;/code&gt; compulsory if function takes 0 params. (otherwise we'll end up getting error 😂). &lt;br&gt;&lt;br&gt;
👉 If Arrow function takes single param , then the parentheses are optional.&lt;/p&gt;
&lt;h3&gt;
  
  
  Bonus🎁 : Concise arrow functions
&lt;/h3&gt;

&lt;p&gt;👉 Concise arrow functions are more optimized than normal arrow functions &lt;br&gt;&lt;br&gt;
👉 Concise arrow functions can be used where we've only return expression in our function body (&lt;code&gt;no {} curly parentheses&lt;/code&gt;) &lt;br&gt;&lt;br&gt;
👉 No need to write &lt;code&gt;return&lt;/code&gt; explicitly in concise arrow functions &lt;br&gt;&lt;br&gt;
👉 Not every arrow function can be converted to Concise arrow function&lt;/p&gt;

&lt;p&gt;👉 *&lt;em&gt;Example : *&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// making sum arrow function concise 
var sum = (num1,num2) =&amp;gt; num1+num2;

sum(1,3); // returns 4

var cube = num1 =&amp;gt; num1*num2;

cube(2); // returns 4

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Notice we haven't converted &lt;code&gt;licenseValidator&lt;/code&gt; to concise arrow function because that function has some amount of calculations inside it's body. &lt;br&gt; &lt;/p&gt;

&lt;p&gt;👉 That's what i meant when i wrote &lt;strong&gt;'not all arrow functions can be converted to concise arrow functions'&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let me know in comment section if you have any doubt or feedback. it's always worth to give time to the thriving developer community :) &lt;br&gt;
&lt;br&gt;
Keep Coding ❤
&lt;/p&gt;

&lt;h4&gt;
  
  
  Hey , Let' Connect👋
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://twitter.com/codarsh"&gt;Twitter&lt;/a&gt; / &lt;a href="https://github.com/WhoAdarshPandya/"&gt;Github&lt;/a&gt; &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>Enough JavaScript to get you Started : #14 Understanding DOM</title>
      <dc:creator>Adarsh Pandya</dc:creator>
      <pubDate>Wed, 20 Jan 2021 07:15:57 +0000</pubDate>
      <link>https://dev.to/whoadarshpandya/enough-javascript-to-get-you-started-14-understanding-dom-1m6c</link>
      <guid>https://dev.to/whoadarshpandya/enough-javascript-to-get-you-started-14-understanding-dom-1m6c</guid>
      <description>&lt;h3&gt;
  
  
  What is DOM?
&lt;/h3&gt;

&lt;p&gt;👉 The Document Object Model (DOM) is a programming interface for HTML and XML documents. It represents the page so that programs can change the document structure, style, and content. The DOM represents the document as nodes and objects. That way, programming languages can connect to the page.&lt;/p&gt;

&lt;h3&gt;
  
  
  Throw this out of the window , I'm Confused 😵
&lt;/h3&gt;

&lt;p&gt;👉 Okay so let me give you a simple definition which will make your concepts clear. DOM represents all the HTML hierarchy for better access in JavaScript -&amp;gt; DOM have document object -&amp;gt; which have all of our HTML elements with structure and styling. &lt;/p&gt;

&lt;p&gt;👉 DOM is there so we can play with elements within JavaScript directly we don't need any intermediate in between HTML and JS. it represent all the HTML elements with their attributes and styling.&lt;/p&gt;

&lt;h3&gt;
  
  
  DOM in visual context
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1610104541530%2F20Degp6ew.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1610104541530%2F20Degp6ew.png" alt="Artboard – 11.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Need of DOM
&lt;/h3&gt;

&lt;p&gt;👉 &lt;strong&gt;Story&lt;/strong&gt; : consider making a greeting website which says good morning on the click of button , you can not do that with simple HTML. adding more to it , suppose you want some styling to be applied dynamically that can be only possible through DOM&lt;/p&gt;

&lt;p&gt;👉 DOM Creates a snapshot of our HTML code with Hierarchy and can be used to play with HTML directly from JS&lt;/p&gt;

&lt;p&gt;👉 in very very simple words , DOM is there so you can manipulate ,add ,remove elements , add / remove styling of elements , get/set/remove HTML attributes like &lt;code&gt;src&lt;/code&gt; and &lt;code&gt;href&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;👉 DOM can be used for&lt;br&gt; &lt;br&gt;&lt;br&gt;
👉 Selecting Elements&lt;br&gt;&lt;br&gt;
👉 Manipulating them&lt;br&gt;&lt;br&gt;
👉 Changing their styles and attributes&lt;br&gt;&lt;br&gt;
👉 Adding events statically/dynamically &lt;br&gt;&lt;br&gt;
👉 Traversing through child and parent elements&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1610104665340%2F5wYslLtsO.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1610104665340%2F5wYslLtsO.png" alt="JavaScript-DOM-Node-Relationships.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  What we'll be covering? 📓
&lt;/h3&gt;

&lt;p&gt;👉 We'll create a greeting app which will cover selecting and manipulating elements as well as styles 😁&lt;/p&gt;

&lt;p&gt;👉 Completing whole DOM is beyond the scope of this article , i strongly suggest you to read full article on  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction" rel="noopener noreferrer"&gt;MDN&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;👉 We'll go through&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Selecting Elements&lt;/li&gt;
&lt;li&gt;Adding events through addEventListener&lt;/li&gt;
&lt;li&gt;Working with attributes&lt;/li&gt;
&lt;li&gt;Manipulating Styles &lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Selecting Elements
&lt;/h3&gt;

&lt;p&gt;👉 Selecting Element from DOM can be tricky , though we can select elements with above mentioned techniques&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;getElementById()&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;&lt;code&gt;getElementsByClassName()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;getElementsByTagName()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;querySelector()&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;👉 &lt;strong&gt;getElementById&lt;/strong&gt; takes name of id given in HTML and returns node so that we can change or manipulate That node with JS.&lt;/p&gt;

&lt;p&gt;👉 in &lt;code&gt;index.html&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;greet&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="style.css"&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
    &amp;lt;h1 class="hide" id="heading1"&amp;gt;Hey , How Are you?&amp;lt;/h1&amp;gt;
    &amp;lt;br /&amp;gt;
    &amp;lt;button id="btn"&amp;gt;get greeting&amp;lt;/button&amp;gt;
    &amp;lt;script src="app.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 in &lt;code&gt;app.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// selecting node by id
var greet = document.getElementById("heading1");
// changing text of node
greet.textContent = "Hello world";

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 this JavaScript can select the node with "heading1" and assigns it text of "Hello World"&lt;br&gt;
&lt;/p&gt;


&lt;p&gt;👉 &lt;code&gt;getElementsByClassName&lt;/code&gt; takes &lt;code&gt;className&lt;/code&gt; as parameter and returns list of matched nodes who're having className same as param.&lt;/p&gt;

&lt;p&gt;👉 in &lt;code&gt;index.html&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;greet&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="style.css"&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
    &amp;lt;h1 class="header"&amp;gt;Hey , How Are you?&amp;lt;/h1&amp;gt;
    &amp;lt;br /&amp;gt;
    &amp;lt;button id="btn"&amp;gt;get greeting&amp;lt;/button&amp;gt;
    &amp;lt;script src="app.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 in &lt;code&gt;app.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// selecting node by className
// notice we're selecting first node from the list by writing '[0]'
var greet = document.getElementsByClassName("header")[0];
// changing text of node
greet.textContent = "Hello world";

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;br&gt;
👉 &lt;code&gt;getElementsByTagName&lt;/code&gt; takes name of tag like &lt;code&gt;h1&lt;/code&gt;,&lt;code&gt;p&lt;/code&gt;,&lt;code&gt;a&lt;/code&gt; as a parameter and returns array of matching node elements from DOM tree. &lt;br&gt;
 

&lt;p&gt;👉 &lt;code&gt;querySelector&lt;/code&gt; takes className or Id as parameter and select the first node element&lt;/p&gt;

&lt;p&gt;👉 if we are passing a class then we've to prefix class with &lt;code&gt;.&lt;/code&gt; like &lt;code&gt;.active&lt;/code&gt; and if we pass id we've to pass it like &lt;code&gt;#id&lt;/code&gt; .&lt;/p&gt;

&lt;p&gt;👉 in &lt;code&gt;index.html&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;greet&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="style.css"&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
    &amp;lt;h1 id="header"&amp;gt;Hey , How Are you?&amp;lt;/h1&amp;gt;
    &amp;lt;br /&amp;gt;
    &amp;lt;button id="btn"&amp;gt;get greeting&amp;lt;/button&amp;gt;
    &amp;lt;script src="app.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 in &lt;code&gt;app.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var greet = document.querySelector("#header");
// changing text of node
greet.textContent = "Hello world";

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;h3&gt;
  
  
  Changing the styling of node elements
&lt;/h3&gt;

&lt;p&gt;👉 Changing the styling of node elements can be done using 2 ways &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;using style&lt;/li&gt;
&lt;li&gt;using classList&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;👉 Changing Background color od body using style property&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.body.style.backgroundColor = "red";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Appending a css class (red) using ClassList&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.body.classList.add("red");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;h3&gt;
  
  
  Changing Attributes of Attributes
&lt;/h3&gt;

&lt;p&gt;👉 Consider you have to change background color or image at runtime, you can't do that statically in HTML&lt;/p&gt;

&lt;p&gt;👉DOM also provides methods for setting or manipulating(adding/removing/changing) attributes when some event gets triggered or even without events&lt;/p&gt;

&lt;p&gt;👉 Changing Body Color of &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; and src of &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; with JS&lt;br&gt;
&lt;br&gt;&lt;br&gt;
👉 in &lt;code&gt;index.html&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;Document&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
    &amp;lt;img id="img" src="" alt=""&amp;gt;
    &amp;lt;script src="./main.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 in &lt;code&gt;main.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// setting bg color property of body to red
document.body.setAttribute("bgcolor", "red");
// setting src property of img to some image
document
  .getElementById("img")
  .setAttribute("src", "2.jpg");

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 &lt;code&gt;setAttibute&lt;/code&gt; is used to set value of HTML attributes which takes 2 params namely name of attribute and the value we want to set !&lt;/p&gt;

&lt;p&gt;👉 Notice that i've written &lt;code&gt;document.getElementById("img").setAttribute("src", "2.jpg");&lt;br&gt;
&lt;/code&gt; in code , this is known as method chaining.&lt;/p&gt;

&lt;p&gt;👉 method chaining is used to achieve same target but  without storing that node/element in some variables which is not needed (results in code optimization 😁)&lt;/p&gt;

&lt;p&gt;👉 In the same way &lt;code&gt;getAttribute()&lt;/code&gt; takes name of attribute of element and return that attribute's value. &lt;/p&gt;

&lt;p&gt;👉 &lt;code&gt;removeAttribute()&lt;/code&gt; also takes name of attribute and removes that particular attribute from HTML .&lt;/p&gt;



&lt;h3&gt;
  
  
  Event Listeners
&lt;/h3&gt;

&lt;p&gt;👉 Event listeners are used to determine what happens when some event is triggered&lt;/p&gt;

&lt;p&gt;👉 so , for example i've button in &lt;code&gt;index.html&lt;/code&gt; and i want to &lt;code&gt;console.log()&lt;/code&gt; something on the click of button click i've to attach eventListener to button.&lt;/p&gt;

&lt;p&gt;👉 in &lt;code&gt;index.html&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;Document&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
    &amp;lt;button id="btn"&amp;gt;click me&amp;lt;/button&amp;gt;
    &amp;lt;script src="./main.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 in &lt;code&gt;main.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var btn = document.getElementById("btn");

btn.addEventListener("click", function () {
  console.log("hello user");
});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 &lt;code&gt;addEventListener&lt;/code&gt; is used for adding event listeners to HTML elements so we can do something with JS as an when that event happens.&lt;/p&gt;

&lt;p&gt;👉 &lt;code&gt;addEventListener&lt;/code&gt; takes 2 params, namely name of event ('click' in our case) and a function which tells events listener what to do when event happens (greeting user in our case).&lt;/p&gt;

&lt;p&gt;👉 Notice that this function doesn't have name , these kind of functions are also known as anonymous functions because they're triggered as an when some event happens so they don't need any name.&lt;/p&gt;



&lt;h3&gt;
  
  
  Making an greeting app
&lt;/h3&gt;

&lt;p&gt;👉 &lt;strong&gt;definition :&lt;/strong&gt; when end user clicks on greet button JS need to load image depending on morning time or evening time &lt;/p&gt;

&lt;p&gt;👉 We'll use all of these things which we've learnt previously and &lt;code&gt;Date()&lt;/code&gt; object which will give us exact hours for passing it into condition and changing content dynamically&lt;/p&gt;

&lt;p&gt;👉 in &lt;code&gt;index.html&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;greet&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="style.css"&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
    &amp;lt;h1 class="hide" id="heading1"&amp;gt;Hey , How Are you?&amp;lt;/h1&amp;gt;
    &amp;lt;br /&amp;gt;
    &amp;lt;button id="btn"&amp;gt;get greeting&amp;lt;/button&amp;gt;
    &amp;lt;script src="app.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 in &lt;code&gt;app.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// selecting elements
var btn = document.getElementById("btn");
var greet = document.getElementById("heading1");

// attaching event on click
btn.addEventListener("click", function () {
  // getting exact hour
  var hour = new Date().getHours();
// checking condition  
if (hour &amp;lt;= 12) {
    document.body.style.backgroundImage =
      "url('./morning.jpg')";
    greet.textContent = "Good Morning !";
  } else {
    document.body.style.backgroundImage =
      "url('./evening.jpg')";
    greet.textContent = "Good Evening!";
  }

  document.body.style.backgroundPosition = "center";
  document.body.style.backgroundSize = "cover";
  document.body.style.backgroundRepeat = "no-repeat";
  // hiding button
  btn.classList.add("hide");
  // display the greeting
  greet.classList.remove("hide");
});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Praise yourselves, you've came this far 🎉&lt;/p&gt;

&lt;p&gt;Let me know in comment section if you have any doubt or feedback. it's always worth to give time to the thriving developer community :) &lt;br&gt;
&lt;br&gt;
Keep Coding ❤
&lt;/p&gt;

&lt;h4&gt;
  
  
  Hey , Let' Connect👋
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://twitter.com/codarsh" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; / &lt;a href="https://github.com/WhoAdarshPandya/" rel="noopener noreferrer"&gt;Github&lt;/a&gt; &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>Enough JavaScript to get you Started : #13 OOP in JS Practical Guide 👩‍💻👨‍💻</title>
      <dc:creator>Adarsh Pandya</dc:creator>
      <pubDate>Tue, 19 Jan 2021 09:07:13 +0000</pubDate>
      <link>https://dev.to/whoadarshpandya/enough-javascript-to-get-you-started-13-oop-in-js-practical-guide-2ffg</link>
      <guid>https://dev.to/whoadarshpandya/enough-javascript-to-get-you-started-13-oop-in-js-practical-guide-2ffg</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1610080617418%2FPTPhskNA4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1610080617418%2FPTPhskNA4.png" alt="tutorial-cover.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Classes and Objects
&lt;/h3&gt;

&lt;p&gt;👉 To summarize previous article , classes are nothing but a template or blue print which decides how object will look and behave with different props/methods.&lt;/p&gt;

&lt;p&gt;👉 We're Using OOP concepts because it provides us Encapsulation and Abstraction. &lt;/p&gt;

&lt;h3&gt;
  
  
  Enough ! Time to open VS code
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1610078108814%2F-Gt4QAFi5.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1610078108814%2F-Gt4QAFi5.jpeg" alt="GettyImages-119721301-0718585.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;👉 Start a new project , and go to &lt;code&gt;app.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;👉 Let's make a Speedometer class &lt;/p&gt;

&lt;p&gt;👉 Speedometer have properties like speed and type&lt;/p&gt;

&lt;p&gt;👉 Speedometer will be having methods like increase and decrease speed&lt;/p&gt;

&lt;p&gt;👉 in &lt;code&gt;app.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Speedometer {
  speed = 0;
  type = "km/h";
  constructor(speed, type) {
    this.speed = speed;
    this.type = type;
  }
  increaseSpeed() {
    this.speed += 10;
  }
  decreaseSpeed() {
    this.speed -= 10;
  }
  getInfo() {
    console.log(this.speed);
    console.log(this.type);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 If we decode our class there are two methods for increasing and decreasing speed of speedometer , and one method for showing information to user.&lt;/p&gt;

&lt;p&gt;👉 Constructor is special function called automatically while creating object. we've used it to initialize initial speed and type of object.&lt;/p&gt;

&lt;p&gt;👉 As of now class don't consume any resources but when we make objects they will surely occupy resources.&lt;/p&gt;

&lt;p&gt;👉 Notice that by convention class names are always written in Pascal case&lt;/p&gt;

&lt;p&gt;👉 Notice we haven't typed &lt;code&gt;var&lt;/code&gt; or &lt;code&gt;let&lt;/code&gt; and even &lt;code&gt;function&lt;/code&gt; to specify in class. we don't need to specify that in class&lt;/p&gt;

&lt;p&gt;👉 Currently(and even by default) we haven't specified and member access specifiers so our methods and props are accessible inside as well as outside the class.&lt;/p&gt;

&lt;h3&gt;
  
  
  Making Object 🌚
&lt;/h3&gt;

&lt;p&gt;👉 Making Object of respective class simply means creating variable of that class. &lt;/p&gt;

&lt;p&gt;👉 we'll use &lt;code&gt;new&lt;/code&gt; keyword to allot resources to new object which we're creating.🏠&lt;/p&gt;

&lt;p&gt;👉 The parentheses takes arguments specified in constructor parameters to initialize starter object 😁&lt;/p&gt;

&lt;p&gt;👉 in &lt;code&gt;app.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var speedoMeter = new Speedmeter(0,"km/h");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 now &lt;code&gt;speedoMeter&lt;/code&gt; is object of class Speedometer with initial value of &lt;code&gt;speed:0&lt;/code&gt; and &lt;code&gt;type : "km/h"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;👉&lt;code&gt;speedoMeter&lt;/code&gt; can now access props and methods like increase and decrease speed&lt;/p&gt;

&lt;p&gt;👉 Go ahead and try calling different methods&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;object1.getInfo();
object1.increaseSpeed();
object1.increaseSpeed();
object1.getInfo();
object1.decreaseSpeed();
object1.getInfo();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 this will output in console&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0
km/h
20
km/h
10
km/h
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What is &lt;code&gt;this&lt;/code&gt;?
&lt;/h3&gt;

&lt;p&gt;👉 this keyword in JavaScript refers to current running object &lt;br&gt;&lt;/p&gt;

&lt;p&gt;👉 it's like we're addressing speedoMeter object with &lt;code&gt;this&lt;/code&gt;, so &lt;code&gt;this&lt;/code&gt; refers to the instance which is in execution now.&lt;/p&gt;

&lt;p&gt;👉 in speedoMeter object we can say like &lt;code&gt;this&lt;/code&gt; object have intial &lt;code&gt;speed of 0 and type of "km/h"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;👉 Notice if in class we want to refer the current running object (which is not there at the moment of creation of class) we'll use &lt;code&gt;this&lt;/code&gt; to access props of current running object.&lt;/p&gt;

&lt;p&gt;👉 so if we write like &lt;code&gt;this.speed&lt;/code&gt; it will refer to speedoMeter object which we have created afterwards.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using member access specifiers
&lt;/h3&gt;

&lt;p&gt;👉 '#' is used to make any property or method of the class private.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;👉 Private methods or props are only accessed inside class&lt;br&gt;&lt;/p&gt;

&lt;p&gt;👉 Accessing private members outside class will result in error&lt;br&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Speedometer {
  #speed = 0;
  #type = "km/h";

  increaseSpeed() {
    this.#speed += 10;
  }
  #decreaseSpeed() {
    this.#speed -= 10;
  }
  getInfo() {
    console.log(this.#speed);
    console.log(this.#type);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Notice that now if we create object of Speedometer the object can now only access increaseSpeed() and getInfo() because other members are private&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(object1.speed) ❌
console.log(object1.type) ❌
object1.getInfo(); ✅
object1.increaseSpeed(); ✅
object1.increaseSpeed(); ✅
object1.getInfo(); ✅
object1.decreaseSpeed(); ❌
object1.getInfo(); ✅
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;h3&gt;
  
  
  Inheritance
&lt;/h3&gt;

&lt;p&gt;👉 Inheritance refers to deriving methods and props of parent class or super class to it's child class or sub class.&lt;/p&gt;

&lt;p&gt;👉 Inheritance increases code reusability in our code&lt;/p&gt;

&lt;p&gt;👉 now , think in terms of animals all animals have &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;color&lt;/code&gt;, so what we can do is rather specifying this properties each and every time in new animal we can make a parent class with all these properties and a greet method which serves purpose of greeting.&lt;/p&gt;

&lt;p&gt;👉 Syntax : &lt;code&gt;class SubClass extends ParentClass&lt;/code&gt;  that's it 😎 now we can use parent class's props and methods in child class 🎉&lt;/p&gt;

&lt;p&gt;👉 Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Animal {
  color;
  name;

  greet() {
    console.log("hey i'm " + this.name);
    console.log("my color is " + this.color);
  }
}

class Dog extends Animal {
  constructor(name, color) {
    super();
    this.name = name;
    this.color = color;
  }
}

var dog = new Dog("tommy", "brown");
dog.greet();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hey i'm tommy
my color is brown
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Notice if we call constructor of sub class it's compulsory to call parent class's constructor regardless of constructor is having params or not.&lt;/p&gt;

&lt;p&gt;👉 Using a reserved keyword known as super we can call parent class's constructor like =&amp;gt; &lt;strong&gt;super();&lt;/strong&gt; or &lt;strong&gt;super(name,color)&lt;/strong&gt; [if constructor is having params]&lt;/p&gt;

&lt;p&gt;👉 Something looks strange? we are using &lt;code&gt;color&lt;/code&gt;,&lt;code&gt;name&lt;/code&gt; and &lt;code&gt;greet()&lt;/code&gt; inside as well as outside Dog class even though these props and methods wasn't declared in Dog class.&lt;/p&gt;

&lt;p&gt;👉 That's how inheritance works, it simple words it will copy all the public and protected methods and props in child class which result in code reusability😀&lt;/p&gt;

&lt;p&gt;Let me know in comment section if you have any doubt or feedback. it's always worth to give time to thriving developer community :) &lt;br&gt;
&lt;br&gt;
Keep Coding ❤
&lt;/p&gt;

&lt;h4&gt;
  
  
  Hey , Let' Connect👋
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://twitter.com/codarsh" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; / &lt;a href="https://github.com/WhoAdarshPandya/" rel="noopener noreferrer"&gt;Github&lt;/a&gt; &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>100daysofcode</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Enough JavaScript to get you Started : #12 Object Oriented JS (Theory)</title>
      <dc:creator>Adarsh Pandya</dc:creator>
      <pubDate>Mon, 18 Jan 2021 06:21:00 +0000</pubDate>
      <link>https://dev.to/whoadarshpandya/enough-javascript-to-get-you-started-12-object-oriented-js-theory-4f4c</link>
      <guid>https://dev.to/whoadarshpandya/enough-javascript-to-get-you-started-12-object-oriented-js-theory-4f4c</guid>
      <description>&lt;h3&gt;
  
  
  What is Object oriented programming ?
&lt;/h3&gt;

&lt;p&gt;👉 So far we've learnt functional JavaScript (process of making app using pure functions avoiding state, objects and mutability) whereas in Object oriented js we'll think in terms of real life examples which introduces us to class , objects , inheritance etc ...&lt;/p&gt;

&lt;p&gt;👉 Object Oriented approach is used to remove &lt;strong&gt;Spaghetti code ()&lt;/strong&gt; ,and making it fully object dependent which groups related properties together.&lt;/p&gt;

&lt;p&gt;👉 Removing Spaghetti code simply means removing unstructured and difficult to maintain source code.&lt;/p&gt;

&lt;p&gt;👉 Notice that Objects we're talking about are as real as us in terms of methodology. These article covers only basics of OOP , there are much more things which are way beyond the scope of this article. for the sake of easiness we'll learn basics first.&lt;/p&gt;

&lt;p&gt;👉 OOP is an art to knot Object's related data and function together , in terms of OOP data and functions are known as properties or methods&lt;/p&gt;

&lt;h3&gt;
  
  
  Problem with Functional JS
&lt;/h3&gt;

&lt;p&gt;👉 Let's say you're making a racing game. so now there are many components in system which come into play but mainly there are two namely User and Cycle&lt;/p&gt;

&lt;p&gt;👉 Now thinking in terms of functional programming , we'll need to specify lots of variables and functions here and there&lt;/p&gt;

&lt;p&gt;👉 There'll be scattered code in terms of data (color,speed,type,gears) and functions (run,stop,reset)&lt;/p&gt;

&lt;h3&gt;
  
  
  How OOP solves the problem
&lt;/h3&gt;

&lt;p&gt;👉 OOP ties a knot between data[properties] and functions[methods]&lt;br&gt;
making it easy to work with and easy to maintain&lt;/p&gt;

&lt;p&gt;👉 in OOP cycle is an object which have properties like color,speed,type, gears and methods like run,stop,reset but all of these in one large container  &lt;/p&gt;



&lt;h3&gt;
  
  
  Object Oriented Paradigms
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1610040449714%2FKxAKHbpOt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1610040449714%2FKxAKHbpOt.png" alt="Artboard – 10.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Class&lt;/strong&gt; : Class in OOP are blue prints or template which defines how a object will look like or how a object will behave , Classes don't hold any memory resources until their objects are made (in which case object will occupy resources).&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Objects&lt;/strong&gt; : Objects are real instance of classes , which can look and behave in certain way. we can create multiple objects of same class. Objects are also known as variable of class which is defined.&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Constructor&lt;/strong&gt; : A constructor in JS is a special method that is used to initialize objects. The constructor is called as an when object of a class is created. we don't need to call constructors explicitly.&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Member Access Specifiers&lt;/strong&gt; : Member access specifiers are used to abstract or hide unnecessary information from end users. (a user don't need to know how cycle runs in run method 🤷‍♂️).&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Public&lt;/strong&gt; : these props/method can be accessed inside as well as out side of the class.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Private&lt;/strong&gt; : these props/method can be accessed only inside class Private access specifiers are used to achieve abstraction in our program.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Protected&lt;/strong&gt; : Protected simply refers to those props/methods which can be accessed inside class and it's sub classes&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;👉 &lt;strong&gt;Inheritance&lt;/strong&gt; : Inheritance can be defined as using methods and props of one class and using it directly in another class which in this case known as sub class or derived class from parent class.  Inheritance refers to code reusability.&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Encapsulation&lt;/strong&gt; : Encapsulation is an art of wrapping related properties and methods of same object (think of a capsule containing multiple drugs in it). Class basically works on Encapsulation which removes spaghetti code and makes it even more optimized&lt;/p&gt;



&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;👉 So far we've learnt the basic theory of OOP concepts like classes , objects , inheritance and constructors &lt;/p&gt;

&lt;p&gt;👉 In the next article we'll see all of these concepts in action 😀&lt;/p&gt;

&lt;p&gt;Let me know in comment section if you have any doubt or feedback. it's always worth to give time to thriving developer community :) &lt;br&gt;
&lt;br&gt;
Keep Coding ❤
&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>100daysofcode</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Enough JavaScript to get you Started : #11 Functions</title>
      <dc:creator>Adarsh Pandya</dc:creator>
      <pubDate>Sun, 17 Jan 2021 08:01:01 +0000</pubDate>
      <link>https://dev.to/whoadarshpandya/enough-javascript-to-get-you-started-11-functions-g56</link>
      <guid>https://dev.to/whoadarshpandya/enough-javascript-to-get-you-started-11-functions-g56</guid>
      <description>&lt;h3&gt;
  
  
  How to ruin your code (story) ? ☠
&lt;/h3&gt;

&lt;p&gt;👉 As i said earlier , when i was beginning with programming i was so foolish to not to follow coding principles like DRY (don't repeat yourself).&lt;/p&gt;

&lt;p&gt;👉 One definition was assigned to me , which was "write a program where have to do addition of 2 numbers 3 times"&lt;/p&gt;

&lt;p&gt;👉 The code i wrote earlier :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var num1 = propmt("Enter no : ");
var num2 = propmt("Enter no : ");
var res = 0;
res = num1+num2;
console.log(res);
var num3 = propmt("Enter no : ");
var num4 = propmt("Enter no : ");
res = num3+num4;
console.log(res);
var num5 = propmt("Enter no : ");
var num6 = propmt("Enter no : ");
res = num5+num6;
console.log(res);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 This does make sense as a beginner , but when you think in terms of performance optimization , speed and quality of code - this doesn't make any sense. &lt;/p&gt;

&lt;p&gt;👉 After that i was introduced to concept known as Function &lt;/p&gt;

&lt;h3&gt;
  
  
  Functions :
&lt;/h3&gt;

&lt;p&gt;👉 According to internet , &lt;em&gt;Functions are one of the fundamental building blocks in JavaScript. A function in JavaScript is similar to a procedure—a set of statements that performs a task or calculates a value, but for a procedure to qualify as a function, it should take some input and return an output where there is some obvious relationship between the input and the output.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;👉 To put it more simply and making it clear we'll go to our previous definition of 3 times of addition. so what we can say  is that &lt;em&gt;a perfect function is a mechanism to reduce that 3 times repeating code into simple block of code which can work for 3 or 30 or even 300 times depending on logic inside it. function simply means act of writing a reusable code.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Syntax of function
&lt;/h3&gt;

&lt;p&gt;👉 Making a function can be defined in three steps &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Function Definition : telling your compiler that there's a function in our program.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Function Body : Block of code to be executed when function gets called.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Function Call : Calling a function simply tells your compiler that execute the code written in function body in respective context.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  How does that looks like?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1610037771700%2FIMJ3TvQ_x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1610037771700%2FIMJ3TvQ_x.png" alt="Artboard – 9.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;👉 functions takes parameters as input process it in function body and &lt;code&gt;returns&lt;/code&gt; output.&lt;/p&gt;

&lt;p&gt;👉 Parameters simply means input values which function is expecting for further process.&lt;/p&gt;

&lt;p&gt;👉 Arguments means actual value passed to the respective parameter&lt;/p&gt;

&lt;p&gt;👉 Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// sum is name of function
// num1 and num2 are params
function sum(num1,num2){
    // function body
   var res = num1+num2;
   return res;
}

//2 and 5 are actual arguments
// function call ();
sum(2,5);
// outputs 7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Rules
&lt;/h3&gt;

&lt;p&gt;👉 Name of function should be unique &lt;br&gt;&lt;br&gt;
👉 Function should be defined somewhere in program before calling it&lt;br&gt;&lt;br&gt;
👉 Function may or may not take parameters&lt;br&gt;&lt;br&gt;
👉 Function may or may not return value&lt;br&gt;&lt;br&gt;
👉 Function can take 0 to n number of parameters depending on need &lt;br&gt;&lt;br&gt;
👉 Function can be called multiple times during execution &lt;br&gt;&lt;br&gt;
👉 &lt;code&gt;Example of function without params and return statements&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greet(){
      console.log("Good Morning");
}

// can be called n number of times
greet();
greet();
greet();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Let's make it more optimized 😎
&lt;/h3&gt;

&lt;p&gt;👉 We'll take our addition program and turn it into a super optimized code&lt;/p&gt;

&lt;p&gt;👉 &lt;code&gt;in app.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function sum()
{
      var num1 = +prompt("Enter no : ");
      var num2 = +prompt("Enter no : ");
      return num1+num2;
}

//calls function 3 times
for(var i=0;i&amp;lt;3;i++) {
      sum();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let me know in comment section if you have any doubt or feedback. it's always worth to give time to thriving developer community :) &lt;br&gt;
&lt;br&gt;
Keep Coding ❤
&lt;/p&gt;

&lt;h4&gt;
  
  
  Hey , Let' Connect👋
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://twitter.com/codarsh" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; / &lt;a href="https://github.com/WhoAdarshPandya/" rel="noopener noreferrer"&gt;Github&lt;/a&gt; &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>100daysofcode</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Enough JavaScript to get you Started : #10 Objects</title>
      <dc:creator>Adarsh Pandya</dc:creator>
      <pubDate>Sat, 16 Jan 2021 07:27:12 +0000</pubDate>
      <link>https://dev.to/whoadarshpandya/enough-javascript-to-get-you-started-10-objects-28cl</link>
      <guid>https://dev.to/whoadarshpandya/enough-javascript-to-get-you-started-10-objects-28cl</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Everything is Object in JS&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  What are Objects ?
&lt;/h3&gt;

&lt;p&gt;👉 Let's forgot about JS objects and talk about real world objects , every object in real world have certain properties and behaviors.&lt;/p&gt;

&lt;p&gt;👉For Example : Girlfriend 😁 , yes ! girlfriend is object , girlfriend have properties like hairColor,eyeColor,name,number,address,likes,dislikes etc... &lt;/p&gt;

&lt;p&gt;👉 In JavaScript Object can be defined as group of related properties.&lt;/p&gt;

&lt;p&gt;👉 Grouping all the related properties to one thing (ex. Car, GF) makes much more sense , because now it's all stored in one place and is easy to access.&lt;/p&gt;

&lt;p&gt;👉 Objects come under category of &lt;strong&gt;composite&lt;/strong&gt; data type , which means mix and match of primitive data types.&lt;/p&gt;

&lt;h3&gt;
  
  
  How Objects work?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u1gulqIj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1610015370516/TkhbmWqkR.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u1gulqIj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1610015370516/TkhbmWqkR.png" alt="Artboard – 8.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;👉 as we can see we grouped all the related properties under one variable namely &lt;strong&gt;girlfriend&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;👉An object is a collection of properties, and a property is an association between a name (or key) and a value.&lt;/p&gt;

&lt;h3&gt;
  
  
  Before making object keep in mind
&lt;/h3&gt;

&lt;p&gt;👉 Objects always work in key value pair &lt;strong&gt;[eg. name:"john"]&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;👉 Arrays are always objects in JS.&lt;/p&gt;

&lt;p&gt;👉 Functions are always objects in JS.&lt;/p&gt;

&lt;p&gt;👉 Objects are always embedded in curly braces &lt;strong&gt;{}&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Syntax
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var object = {
      property : value,
      property2: value,
      ....
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Girlfriend Object 😍
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let girlFriend = {
     name : "alexa",
     surname : "grace",
     likes: ["reading","football"],
     number : 123456789
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 We can access object properties using "."&lt;/p&gt;

&lt;p&gt;👉 For Example &lt;code&gt;girlFriend.name&lt;/code&gt; gives output "alexa"&lt;/p&gt;

&lt;p&gt;👉 &lt;code&gt;girlFriend.likes&lt;/code&gt; gives us array &lt;code&gt;["reading","football"]&lt;/code&gt; as output&lt;/p&gt;

&lt;p&gt;Let me know in comment section if you have any doubt or feedback. it's always worth to give time to thriving developer community :) &lt;br&gt;
&lt;br&gt;
Keep Coding ❤
&lt;/p&gt;

&lt;h4&gt;
  
  
  Hey , Let' Connect👋
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://twitter.com/codarsh"&gt;Twitter&lt;/a&gt; / &lt;a href="https://github.com/WhoAdarshPandya/"&gt;Github&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>100daysofcode</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Enough JavaScript to get you Started : #9 Array</title>
      <dc:creator>Adarsh Pandya</dc:creator>
      <pubDate>Fri, 15 Jan 2021 16:04:45 +0000</pubDate>
      <link>https://dev.to/whoadarshpandya/enough-javascript-to-get-you-started-9-array-1k00</link>
      <guid>https://dev.to/whoadarshpandya/enough-javascript-to-get-you-started-9-array-1k00</guid>
      <description>&lt;h3&gt;
  
  
  The definition resides in usage of Array
&lt;/h3&gt;

&lt;p&gt;👉 imagine someone gave you a definition which says store all the fruits and display them&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Idea 1 (foolish way to manage things)&lt;/strong&gt; : try to create 30 to 40 variables&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Idea 2 (smarter way to manage things)&lt;/strong&gt; : creating a Array named fruits&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Array anyway?
&lt;/h3&gt;

&lt;p&gt;👉 Arrays are just collection of data types&lt;/p&gt;

&lt;p&gt;👉 I'm sure if you are beginner the line i written above will not make any sense to you&lt;/p&gt;

&lt;p&gt;👉 Imagine creating a one big variable or container which can hold multiple small variables ,so it's easy to access&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Real life example :&lt;/strong&gt; box of chocolates 🍫🍫🍫🍫🍫 which can hold 100s of chocolates , now imagine managing 100 chocolates without box (pretty messed up right ? 🤣)&lt;/p&gt;

&lt;h3&gt;
  
  
  Graphical Representation of Array
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IXNNULd9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1610013264802/Q3G1mQDAR.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IXNNULd9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1610013264802/Q3G1mQDAR.png" alt="Artboard – 7.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;👉 Array holds multiple values, whereas an ordinary variable hold a single value&lt;/p&gt;

&lt;p&gt;👉 Array values must be inside Square braces &lt;strong&gt;[ ]&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;👉 Arrays are index based and index starts from &lt;code&gt;0&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;👉 In simple words if you want to access "Apple", you need to write&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fruits = ["apple","banana","grapes,"cherry"]

console.log(fruits[1]); ❌

console.log(fruits[0]); ✅
// logs "apple"

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Printing Whole Array&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fruits = ["apple","banana","grapes,"cherry"];

console.logs(fruits);

//logs ["apple","banana","grapes,"cherry"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 Iterating over individual elements of array&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;fruits = ["apple","banana","grapes,"cherry"];

// for of generally used for arrays

for (var fruit of fruits)
{
      console.log(fruit);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let me know in comment section if you have any doubt or feedback. it's always worth to give time to thriving developer community :) &lt;br&gt;
&lt;br&gt;
Keep Coding ❤
&lt;/p&gt;

&lt;h4&gt;
  
  
  Hey , Let' Connect👋
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://twitter.com/codarsh"&gt;Twitter&lt;/a&gt; / &lt;a href="https://github.com/WhoAdarshPandya/"&gt;Github&lt;/a&gt; &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>100daysofcode</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Enough JavaScript to get you Started : #8 Loops</title>
      <dc:creator>Adarsh Pandya</dc:creator>
      <pubDate>Thu, 14 Jan 2021 15:45:28 +0000</pubDate>
      <link>https://dev.to/whoadarshpandya/enough-javascript-to-get-you-started-8-loops-46hp</link>
      <guid>https://dev.to/whoadarshpandya/enough-javascript-to-get-you-started-8-loops-46hp</guid>
      <description>&lt;h3&gt;
  
  
  how to not write your code 🎃
&lt;/h3&gt;

&lt;p&gt;👉 okay ! this is going to be a funny story , when i started programming someone challenged me to print 1 to 20 on console. i laughed because it was too easy &lt;/p&gt;

&lt;p&gt;👉 completely out of logic i started typing &lt;code&gt;console.log() for 20&lt;/code&gt; times and yelled &lt;strong&gt;i'm done&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;👉 this is how i wrote progam&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(1)
console.log(2)
console.log(3)
console.log(4)
console.log(5)
console.log(6)
console.log(7)
console.log(8)
console.log(9)
console.log(10)
console.log(11)
console.log(12)
console.log(13)
console.log(14)
console.log(15)
console.log(16)
console.log(17)
console.log(18)
console.log(19)
console.log(20)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 this looks stupid right? 😂 there's a principle in coding world known as &lt;strong&gt;DRY (don't repeat your self)&lt;/strong&gt; and what i did was exact opposite of it 😂&lt;/p&gt;

&lt;h3&gt;
  
  
  Concept of Loops came in picture
&lt;/h3&gt;

&lt;p&gt;👉 After i showed code to my colleagues they said there's something known as loop&lt;/p&gt;

&lt;p&gt;👉 Loops are condition based iterative blocks which repeats themselves n number of time based on condition&lt;/p&gt;

&lt;h3&gt;
  
  
  Types of loop
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;For loop (we'll be learning this ✅)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;While Loop&lt;/li&gt;
&lt;li&gt;Do...while Loop&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Logical flow of Loops
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1610011071740%2FvoRVolcVR.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1610011071740%2FvoRVolcVR.png" alt="Artboard – 6.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  For Loop Syntax
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for(intial value;exit condition;update statement)
{
    // loop body | block
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Refactoring our old code
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for(var i=1;i&amp;lt;20;i++)
{
      console.log(i);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;👉 This syntax makes much more sense then previous one , and follows DRY principle&lt;/p&gt;

&lt;p&gt;👉 meaning of this code : &lt;em&gt;"start from 1 , increase by 1 every time and exit from loop when it becomes greather than 20"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let me know in comment section if you have any doubt or feedback. it's always worth to give time to thriving developer community :) &lt;br&gt;
&lt;br&gt;
Keep Coding ❤
&lt;/p&gt;

&lt;h4&gt;
  
  
  Hey , Let' Connect👋
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://twitter.com/codarsh" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; / &lt;a href="https://github.com/WhoAdarshPandya/" rel="noopener noreferrer"&gt;Github&lt;/a&gt; &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>100daysofcode</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
