<?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: Muskan Chhatrasal</title>
    <description>The latest articles on DEV Community by Muskan Chhatrasal (@muskanchhatrasal).</description>
    <link>https://dev.to/muskanchhatrasal</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%2F708601%2Ff24a43c0-91ed-4700-bd91-24e92792d493.png</url>
      <title>DEV Community: Muskan Chhatrasal</title>
      <link>https://dev.to/muskanchhatrasal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/muskanchhatrasal"/>
    <language>en</language>
    <item>
      <title>Compiler &amp; Transpiler</title>
      <dc:creator>Muskan Chhatrasal</dc:creator>
      <pubDate>Sat, 12 Feb 2022 17:07:41 +0000</pubDate>
      <link>https://dev.to/muskanchhatrasal/compiler-transpiler-17nh</link>
      <guid>https://dev.to/muskanchhatrasal/compiler-transpiler-17nh</guid>
      <description>&lt;p&gt;To Understand the difference between a &lt;strong&gt;Transpiler&lt;/strong&gt; and a &lt;strong&gt;Compiler&lt;/strong&gt;&lt;br&gt;
, we first need to understand what is a compiler and what is a transpiler.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;compiler&lt;/strong&gt; takes in some code as input and produces a binary executable code aka machine code as output. For example - we use GCC compiler to compile the &lt;strong&gt;C/C++&lt;/strong&gt; code and it produces the machine code.&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%2Fv1641719701412%2FgrAiaVThD.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" 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%2Fv1641719701412%2FgrAiaVThD.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="'Image description'"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Transpilers&lt;/strong&gt; aka source-to-source compilers read the code in one language and produce the code in another language.&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%2Fv1641719432278%2FTPthn9AJ3.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" 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%2Fv1641719432278%2FTPthn9AJ3.png%3Fauto%3Dcompress%2Cformat%26format%3Dwebp" alt="'Image description'"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ES6 version:
let a=10;
console.log(a);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ES6 to ES5 (Transpiling):
var a=10;
console.log(a);

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

&lt;/div&gt;



&lt;p&gt;For Example, A &lt;strong&gt;Transpiler&lt;/strong&gt; will convert a code from Java to kotlin whereas a &lt;strong&gt;Compiler&lt;/strong&gt; will convert Java into bytecode. Similarly, A &lt;strong&gt;Transpiler&lt;/strong&gt; will convert a code from python to Javascript whereas a &lt;strong&gt;Compiler&lt;/strong&gt; will convert a code from Java to bytecode.&lt;/p&gt;

&lt;p&gt;This was my honest try to make you understand the difference better with diagrams as we have a photographic memory and this way it stays long. Do let me know if I need to add more to this and how can I improve more.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How JS is executed &amp; Call Stack</title>
      <dc:creator>Muskan Chhatrasal</dc:creator>
      <pubDate>Sun, 19 Sep 2021 09:59:19 +0000</pubDate>
      <link>https://dev.to/muskanchhatrasal/how-js-is-executed-call-stack-511d</link>
      <guid>https://dev.to/muskanchhatrasal/how-js-is-executed-call-stack-511d</guid>
      <description>&lt;p&gt;Exactly when a JS program is ran, a global execution context is made.The execution setting is made in two phases:-&lt;br&gt;
Memory creation stage - JS will dole out memory to variables and functions. &lt;br&gt;
Code execution stage. &lt;/p&gt;

&lt;h2&gt;
  
  
  What about we think about the accompanying code and it's execution:
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;var n = 5; &lt;br&gt;
function square(num){ &lt;br&gt;
var ans = num*num; &lt;br&gt;
return back; &lt;br&gt;
} &lt;br&gt;
var sqr2 = square(n); &lt;br&gt;
var sqr4 = square(4);&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;Indisputably the &lt;strong&gt;primary&lt;/strong&gt; thing which JS does is &lt;strong&gt;memory creation stage,&lt;/strong&gt; so it goes to line one of the above code digit, and award a memory space for variable &lt;strong&gt;'n'&lt;/strong&gt; and a short time later goes to line two, and &lt;strong&gt;allocates a memory space&lt;/strong&gt; for &lt;strong&gt;function 'square'&lt;/strong&gt;. While disseminating memory &lt;strong&gt;for n it stores 'undefined'&lt;/strong&gt;, an exceptional incentive for 'n'. &lt;strong&gt;For 'square', it stores the whole code of the capacity inside its memory space.&lt;/strong&gt; Then, as sqr2 and sqr4 are factors likewise, it assigns memory and stores 'undefined' for them, and this is the completion of first stage for example memory creation stage.&lt;/p&gt;

&lt;h3&gt;
  
  
  So O/P will look something like
&lt;/h3&gt;

&lt;p&gt;Execution Context Phase 1 &lt;/p&gt;

&lt;p&gt;By and by, in &lt;strong&gt;second stage&lt;/strong&gt; for instance code execution stage, it starts going through the whole code line by line. As it encounters var n=2, it designate 2 to 'n'. So far, the value of 'n' was indistinct. For function, there is nothing to execute. As these lines were by then overseen in memory creation stage.&lt;/p&gt;

&lt;p&gt;Coming to line 6 for instance &lt;strong&gt;var sqr2 = square(n),&lt;/strong&gt; &lt;strong&gt;here functions are fairly not equivalent to another dialect. Another execution setting is made by and large.&lt;/strong&gt; Again in this new execution setting, in memory creation stage, we assign memory to num and ans the two factors. Likewise, undefined is placed in them. As of now, in code execution setting, beginning 2 is named to num. Then, var ans = num*num will store 4 in ans. Starting now and into the foreseeable future, get ans gets the control of program back to where this function was conjured from.&lt;/p&gt;

&lt;p&gt;Execution Context Phase 2 &lt;/p&gt;

&lt;p&gt;Right when return watchword is capable, it returns the control to the called line and moreover the capacity setting is eradicated. Same thing will be reiterated for sqr4 and subsequently after that is done, the worldwide execution setting will be obliterated. So the last chart before deletion would look something like: &lt;/p&gt;

&lt;p&gt;Execution Context Phase 2 &lt;/p&gt;

&lt;p&gt;JavaScript directs code execution setting creation and eradication with the help of &lt;strong&gt;Call Stack.&lt;/strong&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  Call Stack
&lt;/h2&gt;

&lt;p&gt;Call stack is a system to screen its place in script that calls different capacities. &lt;/p&gt;

&lt;p&gt;Call stack monitors everything of execution context. It is generally called &lt;strong&gt;Program Stack, Control Stack, Runtime Stack, Machine stack, Execution Context Stack.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Hoisting in JavaScript</title>
      <dc:creator>Muskan Chhatrasal</dc:creator>
      <pubDate>Sun, 19 Sep 2021 08:08:16 +0000</pubDate>
      <link>https://dev.to/muskanchhatrasal/hoisting-in-javascript-5gga</link>
      <guid>https://dev.to/muskanchhatrasal/hoisting-in-javascript-5gga</guid>
      <description>&lt;p&gt;Hoisting is the default behavior of JavaScript where all the variable and function declarations are moved on top. 🔼&lt;/p&gt;

&lt;p&gt;Points ↖️ to Remember :&lt;/p&gt;

&lt;p&gt;👉JavaScript compiler moves 🚵 variables and function declaration to the 🤘 top🔼 and this is called hoisting.&lt;/p&gt;

&lt;p&gt;👉Only variable declarations move 🚴 to the 🤘 top, ⤴️ not the 🤘 initialization.&lt;/p&gt;

&lt;p&gt;👉Functions definition moves 🚵🚶 first 🌓 before variables.&lt;/p&gt;

&lt;p&gt;👉This means 😏 that irrespective of where the variables and functions are declared, they 💁 are moved on top ⬆️ of the scope.&lt;br&gt;
The 🤘 scope can be both local and global.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why does JavaScript hoist variables?
&lt;/h2&gt;

&lt;p&gt;when you run your js code :&lt;br&gt;
global execution context(just a wrapper) is created&lt;/p&gt;

&lt;p&gt;It is created in 2 phases&lt;br&gt;
1) creation phase&lt;br&gt;
2)Execution phase&lt;/p&gt;

&lt;p&gt;In the creation phase &lt;strong&gt;javascript engine&lt;/strong&gt; allocates memory to all variables and function in the code and important thing is entire function(fun body) will sit in that memory block and coming to variables in the creation engine don't know what the variable value is going to be by the end because we can manipulate it later&lt;br&gt;
&lt;strong&gt;in the code right ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So in the creation phase instead of storing actul value it will undefined(a placeholder or a sticker)&lt;br&gt;
&lt;code&gt;ex = myName : undefined&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Hoisting in Function checked variable
&lt;/h2&gt;

&lt;p&gt;We should figure out how Hoisting of capacity checked factors happens with the accompanying model:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;//function scoped&lt;br&gt;
function myFunc(){&lt;br&gt;
console.log(car);&lt;br&gt;
var vehicle = 'Lamborgini';&lt;br&gt;
}&lt;br&gt;
myFunc(); //undefined&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How is hoisting related with scoping in JavaScript?
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;scope manages the accessibility of variables.&lt;/strong&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;h2&gt;
  
  
  Hopefully, my post has helped you understand the hoisting better!
&lt;/h2&gt;

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