<?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: Aayush Jain</title>
    <description>The latest articles on DEV Community by Aayush Jain (@aayushjaincode).</description>
    <link>https://dev.to/aayushjaincode</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%2F707284%2F8c27e45d-c827-415b-bdda-73a5ee2f0bbb.jpeg</url>
      <title>DEV Community: Aayush Jain</title>
      <link>https://dev.to/aayushjaincode</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aayushjaincode"/>
    <language>en</language>
    <item>
      <title>What is Function Statement/Declarations in JavaScript?</title>
      <dc:creator>Aayush Jain</dc:creator>
      <pubDate>Sat, 12 Feb 2022 14:07:04 +0000</pubDate>
      <link>https://dev.to/aayushjaincode/what-is-function-statementdeclarations-in-javascript-1fbd</link>
      <guid>https://dev.to/aayushjaincode/what-is-function-statementdeclarations-in-javascript-1fbd</guid>
      <description>&lt;h3&gt;
  
  
  Saved for later use = Declared function
&lt;/h3&gt;

&lt;p&gt;A declared function is “saved for later use”, and will be executed later, when it is invoked (called).&lt;/p&gt;

&lt;h3&gt;
  
  
  What is a Function Expression?
&lt;/h3&gt;

&lt;p&gt;A JavaScript function can also be defined using an expression.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A function expression can be stored in a variable:&lt;br&gt;
&lt;code&gt;var x = function (a, b) {return a * b};&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After a function expression has been stored in a variable, the variable can be used as a function. Functions stored in variables do not need function names. They are always invoked (called) using the variable name.&lt;/p&gt;

&lt;h3&gt;
  
  
  Function Expression VS. Function Statement
&lt;/h3&gt;

&lt;p&gt;Example: Function Expression&lt;br&gt;
&lt;code&gt;alert(foo()); // ERROR! foo wasn't loaded yet&lt;br&gt;
var foo = function() { return 5; }&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Function declarations load before any code is executed while Function expressions load only when the interpreter reaches that line of code.&lt;/p&gt;

&lt;p&gt;Example: Function Declaration&lt;br&gt;
&lt;code&gt;alert(foo()); // Alerts 5. Declarations are loaded before any code can run.&lt;br&gt;
function foo() { return 5; }&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Similar to the var statement, function declarations are hoisted to the top of other code. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Hoisting is a concept which enables us to extract values of variables and functions even before initialising/assigning value without getting error and this is happening due to the 1st phase (memory creation phase) of the Execution Context.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;getName(); // Namaste JavaScript&lt;br&gt;
console.log(x); // undefined&lt;br&gt;
console.log(getName); // f getName(){ console.log("Namaste JavaScript); }&lt;br&gt;
function getName(){&lt;br&gt;
    console.log("Namaste JavaScript");&lt;br&gt;
}&lt;/code&gt;&lt;br&gt;
Function expressions aren’t hoisted, which allows them to retain a copy of the local variables from the scope where they were defined.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;getName(); // Uncaught TypeError: getName is not a function&lt;br&gt;
console.log(getName);&lt;br&gt;
var getName = function () {&lt;br&gt;
    console.log("Namaste JavaScript");&lt;br&gt;
}&lt;/code&gt;&lt;br&gt;
// The code won't execute as the first line itself throws an TypeError.&lt;/p&gt;

&lt;h3&gt;
  
  
  Benefits of Function Expressions
&lt;/h3&gt;

&lt;p&gt;There are several different ways that function expressions become more useful than function declarations.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;As closures - Function bundled along with it's lexical scope is closure.&lt;/li&gt;
&lt;li&gt;As arguments to other functions&lt;/li&gt;
&lt;li&gt;As Immediately Invoked Function Expressions (IIFE)&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>What is the Temporal dead zone?</title>
      <dc:creator>Aayush Jain</dc:creator>
      <pubDate>Mon, 10 Jan 2022 05:54:44 +0000</pubDate>
      <link>https://dev.to/aayushjaincode/what-is-the-temporal-dead-zone-30hm</link>
      <guid>https://dev.to/aayushjaincode/what-is-the-temporal-dead-zone-30hm</guid>
      <description>&lt;p&gt;In case of let and const variables, Basically, Temporal Dead Zone is a zone "before your variable is declared",&lt;br&gt;
i.e where you can not access the value of these variables, it will throw an error.&lt;/p&gt;

&lt;p&gt;ex.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let sum = a + 5;        //---------
//some other code       //         | ------&amp;gt;  this is TDZ for variable a
                        //         |
console.log(sum)        //---------
let a = 5;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;above code gives an error&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;the same code will not give an error when we use var for variable 'a',&lt;/p&gt;

&lt;p&gt;ex.&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;                            
console.log(sum)     //prints undefined
var a = 5;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;let and const have two broad differences from var:&lt;/p&gt;

&lt;p&gt;1.They are block scoped.&lt;br&gt;
2.Accessing a var before it is declared has the result undefined; accessing a let or const before it is declared throws ReferenceError:&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(aVar); // undefined
console.log(aLet); // Causes ReferenceError: Cannot access 'aLet' before initialization

var aVar = 1;
let aLet = 2;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It appears from these examples that let declarations (and const, which works the same way) may not be hoisted, since aLet does not appear to exist before it is assigned a value.&lt;/p&gt;

&lt;p&gt;That is not the case, however—let and const are &lt;strong&gt;hoisted (like var, class and function)&lt;/strong&gt;, but &lt;u&gt;there is a period between entering scope and being declared where they cannot be accessed. This period is the &lt;/u&gt;&lt;strong&gt;temporal dead zone (TDZ)&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  To Summarize
&lt;/h2&gt;

&lt;p&gt;Hoisting:&lt;br&gt;
let,const,var are all get hoisted process.&lt;br&gt;
(whats mean they go upper and declare in the top of the scope.)&lt;/p&gt;

&lt;p&gt;hoisting process: var, let, const&lt;br&gt;
Initialisation process: var&lt;/p&gt;




&lt;h3&gt;
  
  
  Thanks, and see you next time!
&lt;/h3&gt;

</description>
    </item>
    <item>
      <title>What is a Promise in JavaScript ?</title>
      <dc:creator>Aayush Jain</dc:creator>
      <pubDate>Fri, 17 Sep 2021 09:10:19 +0000</pubDate>
      <link>https://dev.to/aayushjaincode/what-is-a-promise-javascript-14lb</link>
      <guid>https://dev.to/aayushjaincode/what-is-a-promise-javascript-14lb</guid>
      <description>&lt;h2&gt;
  
  
  What is a Promise?
&lt;/h2&gt;

&lt;p&gt;*(in JavaScript) &lt;/p&gt;

&lt;p&gt;A promise is an article that may 🌌 produce a solitary worth at some point 🕠 later on 📅 with either a settled 💯value or a cause 💬 that it's not 😐 resolved.* &lt;/p&gt;

&lt;h2&gt;
  
  
  How Promises Work
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;𝐈𝐭 𝐰𝐢𝐥𝐥 👏 𝐛𝐞 𝗳𝗮𝗹𝗹𝗶𝗻𝗴 𝗨𝗻𝗱𝗲𝗿 𝐨𝐧𝐞 ☝️ 𝐨𝐟 𝐭𝐡𝐞 𝟑 𝐩𝐨𝐬𝐬𝐢𝐛𝐥𝐞 𝐬𝐭𝐚𝐭𝐞𝐬:&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;👉𝐏𝐞𝐧𝐝𝐢𝐧𝐠: This is an initial stage of the Promise 🤞 previously 🤔 an operation 💁 starts. &lt;/p&gt;

&lt;p&gt;👉𝐅𝐮𝐥𝐟𝐢𝐥𝐥𝐞𝐝: This state demonstrates that 🔀 the specified operation was finished. ✅ &lt;/p&gt;

&lt;p&gt;👉𝐑𝐞𝐣𝐞𝐜𝐭𝐞𝐝: 🚫 This state 🇺🇸 demonstrates that 👉 the operation 💁 didn't finish. In 😩 this case, a blunder 🚫 esteem 👇 will be thrown🙀. &lt;/p&gt;

&lt;h2&gt;
  
  
  𝐖𝐡𝐲 🤔𝐝𝐨 𝐲𝐨𝐮 𝐧𝐞𝐞𝐝 😬 𝐚 𝐩𝐫𝐨𝐦𝐢𝐬𝐞?
&lt;/h2&gt;

&lt;p&gt;Promises are utilized 🚟 to deal with nonconcurrent activities. &lt;/p&gt;

&lt;p&gt;They give 👋 an another way to deal with callbacks by lessening ⏬ the callback hell and composing the cleaner code💻. &lt;/p&gt;

&lt;h2&gt;
  
  
  𝐖𝐡𝐚𝐭 🙌 𝐚𝐫𝐞 𝐭𝐡𝐞 𝐦𝐚𝐢𝐧 𝐫𝐮𝐥𝐞𝐬 𝐨𝐟 𝐩𝐫𝐨𝐦𝐢𝐬𝐞?
&lt;/h2&gt;

&lt;p&gt;🤞 A promise is an item that 🍜 supplies a standard-consistent .then() method &lt;/p&gt;

&lt;p&gt;🤞A forthcoming promise might change into 🤓 either satisfied or dismissed by the state. &lt;/p&gt;

&lt;p&gt;🤞A satisfied or dismissed 🚫 promise 🤞 is settled and it should not ⚙️ change into 👉 any 🕺 other state. &lt;/p&gt;

&lt;p&gt;👆Once a promise 🤞 is settled, the worth 💵 should not ✖️ change. &lt;/p&gt;

&lt;h2&gt;
  
  
  Promise Chaining
&lt;/h2&gt;

&lt;p&gt;Since .then() consistently returns another promise, it's feasible to chain promises with exact power over how and where blunders are taken care of. Promises permit you to imitate typical simultaneous code's attempt/get conduct. &lt;/p&gt;

&lt;h2&gt;
  
  
  What is the contrast among Callbacks and Promises?
&lt;/h2&gt;

&lt;p&gt;A callback function is a function passed into 🚟👉 one more function as a contention. &lt;/p&gt;

&lt;p&gt;This capacity is conjured inside 💠 the external function to finish an activity. 🎬 &lt;/p&gt;

&lt;p&gt;The principle Difference between Callback-functions and Promises is that we Attach a Callback-function to a Promise instead of passing it. &lt;/p&gt;

&lt;p&gt;So we actually use callback functions with Promises, yet in an unexpected way (chaining).&lt;/p&gt;




&lt;p&gt;Hope you found it useful...&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>object</category>
    </item>
    <item>
      <title>Scopes and Hoisting in JavaScript</title>
      <dc:creator>Aayush Jain</dc:creator>
      <pubDate>Thu, 16 Sep 2021 12:26:44 +0000</pubDate>
      <link>https://dev.to/aayushjaincode/scopes-in-javascript-49fi</link>
      <guid>https://dev.to/aayushjaincode/scopes-in-javascript-49fi</guid>
      <description>&lt;p&gt;&lt;em&gt;The scope manages the accessibility of variables.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The Scope decides how far the JavaScript will go to look 🧐 for a variable. In the event that it's doesn't exist in the current extension, 🤪 it'll look 👀 in the external Scope .&lt;/p&gt;

&lt;p&gt;Scope in JavaScript is the area where we have 😒 Correct ✅ access to a variable / function.&lt;/p&gt;

&lt;h1&gt;
  
  
  kinds of scopes in JavaScript —
&lt;/h1&gt;

&lt;h2&gt;
  
  
  𝐁𝐥𝐨𝐜𝐤 𝐒𝐜𝐨𝐩𝐞{...} :- 💯
&lt;/h2&gt;

&lt;p&gt;Block scoped variables are only accessible inside a block brackets. Which can be, inside an if block({....}), function-block, loop(for,while...), or an seperately defined block. Anything in between by curly braces is a block.&lt;/p&gt;

&lt;p&gt;A code block in JavaScript defines a scope for variable declare using let / const as-&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;if (true) {&lt;br&gt;
  // "if" block scope&lt;br&gt;
  const message = 'Aayu';&lt;br&gt;
  console.log(message); // 'Aayu'&lt;br&gt;
}&lt;br&gt;
console.log(message); // throws ReferenceError&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Standalone code blocks&lt;/strong&gt;. The standalone code blocks also creates a scope:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;{&lt;br&gt;
  // block scope&lt;br&gt;
  Let message = 'Aayush';&lt;br&gt;
  console.log(message); // 'Aayush'&lt;br&gt;
}&lt;br&gt;
console.log(message); // throws ReferenceError&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Note: &lt;strong&gt;var is not block scoped&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧 𝐬𝐜𝐨𝐩𝐞 𝐟(){.....}, 💥
&lt;/h2&gt;

&lt;p&gt;Variables Scoped inside a function are only available inside a function.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;function walk() {&lt;br&gt;
  // "Walk" function scope&lt;br&gt;
  var message = 'Walk, fast, walk!';&lt;br&gt;
  console.log(message); // 'Walk, fast, walk!'&lt;br&gt;
}&lt;br&gt;
Walk();&lt;br&gt;
console.log(message); // throws Reference Error&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  𝐆𝐥𝐨𝐛𝐚𝐥 𝐬𝐜𝐨𝐩𝐞 |......| :-
&lt;/h2&gt;

&lt;p&gt;The Variables / functions Which have global scope can be accessed everywhere in the Code-Block or module file.&lt;/p&gt;

&lt;p&gt;A variable announced inside the worldwide extension is named worldwide variable. Worldwide factors are available from any extension. &lt;/p&gt;

&lt;h2&gt;
  
  
  Lexical scope
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;A lexical scope Contains outer scopes declared constantly.&lt;/em&gt;&lt;br&gt;
Let’s define 2 functions, having the function inner() is nested inside outer().&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;function outer() {&lt;br&gt;
  // the outer scope&lt;br&gt;
  let outerVar = 'I am from outside!';&lt;br&gt;
  function inner() {&lt;br&gt;
    // the inner scope&lt;br&gt;
    console.log(outerVar); // 'I am from outside!'&lt;br&gt;
  }&lt;br&gt;
  return inner;&lt;br&gt;
}&lt;br&gt;
const inner = outer();&lt;br&gt;
inner();&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;




&lt;h2&gt;
  
  
  Hopefully, my post has helped you understand the scope better!
&lt;/h2&gt;

</description>
      <category>javascript</category>
      <category>oop</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
