<?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: Zoran Stankovic</title>
    <description>The latest articles on DEV Community by Zoran Stankovic (@ryunosukezoran).</description>
    <link>https://dev.to/ryunosukezoran</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%2F394185%2F16166f6d-f2d7-49c7-a6cd-30cd864a73e1.png</url>
      <title>DEV Community: Zoran Stankovic</title>
      <link>https://dev.to/ryunosukezoran</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ryunosukezoran"/>
    <language>en</language>
    <item>
      <title>Execution Context in JavaScript (Part 1.)</title>
      <dc:creator>Zoran Stankovic</dc:creator>
      <pubDate>Mon, 29 Nov 2021 17:40:37 +0000</pubDate>
      <link>https://dev.to/ryunosukezoran/execution-context-in-javascript-part-1-53fd</link>
      <guid>https://dev.to/ryunosukezoran/execution-context-in-javascript-part-1-53fd</guid>
      <description>&lt;p&gt;In this blog post I will try to give answers to these questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What is the execution context in JavaScript?&lt;/li&gt;
&lt;li&gt;What type of execution context exists?&lt;/li&gt;
&lt;li&gt;What is Hoisting?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;One of the essential concepts in JavaScript is learning about “Execution Context.” Once we understand what it is, it will be much easier for us to understand more advanced topics like Hoisting, Scope chains, and Closures.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Execution Context&lt;/strong&gt; is a concept that describes the environment in which your code is running. Also, it allows the JavaScript engine to manage the complexity of interpreting and running your code.&lt;/p&gt;

&lt;p&gt;Now let us see how we can create an Execution Context. When we run our JavaScript application, even if that is an empty JavaScript file, JavaScript creates the first Execution Context called “Global Execution Context.”&lt;/p&gt;

&lt;h3&gt;
  
  
  Global Execution Context
&lt;/h3&gt;

&lt;p&gt;Initially, this Global Execution Context comprises two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;a &lt;code&gt;global object&lt;/code&gt; and&lt;/li&gt;
&lt;li&gt;a variable called &lt;code&gt;this&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If we execute code in the browser outside of any function, this refers to a global object, which in this case is the window. It doesn’t matter if we are in strict mode.&lt;/p&gt;

&lt;p&gt;If we execute this code in Node, at the top level, this is equivalent to the global object which is called &lt;code&gt;global&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Global Execution Context in Browser and Node REPL&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K4oU-yYu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fny9f8n5utgngoqu9fgn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K4oU-yYu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fny9f8n5utgngoqu9fgn.png" alt="Global Execution Context in Browser and Node REPL" width="581" height="223"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I won’t go into any details here, but in Node this is only true for the REPL. If we execute this code,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nb"&gt;global&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// returns true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;inside of Node REPL, we will get &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--I09DsTPv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cky51f764newu3gtqgpm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--I09DsTPv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cky51f764newu3gtqgpm.png" alt="Node REPL" width="346" height="168"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But inside of the Node &lt;code&gt;module&lt;/code&gt;, execution of the code below will return &lt;code&gt;false&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nb"&gt;global&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HVZBhmZB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eqlo05t5b3y21sxarvfr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HVZBhmZB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eqlo05t5b3y21sxarvfr.png" alt="Code inside of the Node module" width="368" height="195"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is because inside of node module, &lt;code&gt;this&lt;/code&gt; refers to &lt;code&gt;module.exports&lt;/code&gt;. In this blog post, we will focus on Execution Context inside of Browser.&lt;/p&gt;

&lt;p&gt;Execution Context has two phases: &lt;strong&gt;Creation&lt;/strong&gt; and &lt;strong&gt;Execution&lt;/strong&gt; phase. We can see that in the picture below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bzMKCLtu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ojiwpnby6fv3mpci6gk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bzMKCLtu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ojiwpnby6fv3mpci6gk.png" alt="Representation of Global Execution Context in Creation and Execution phase" width="759" height="538"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In Global &lt;code&gt;Creation&lt;/code&gt; phase, JavaScript engine, as we mentioned earlier, will create a &lt;code&gt;global&lt;/code&gt; and &lt;code&gt;this&lt;/code&gt; objects, and also will allocate memory space for &lt;code&gt;variables&lt;/code&gt; and &lt;code&gt;functions&lt;/code&gt;. In this phase, the JavaScript engine will assign to the variable declarations a default value of &lt;code&gt;undefined&lt;/code&gt; but will place whole function declarations in memory. This brings us to one term mentioned at the beginning of this blog post, and that is &lt;code&gt;Hoisting&lt;/code&gt;. We call assigning default value of &lt;code&gt;undefined&lt;/code&gt; to variable declarations in the &lt;code&gt;Creation&lt;/code&gt; phase &lt;code&gt;Hoisting&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Tip&lt;/strong&gt;: It’s always better to first define your variables and then use them, don’t rely on &lt;code&gt;Hoisting&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then JavaScript engine starts to parsing and executing your code line by line. We call this process of code execution &lt;code&gt;thread of execution&lt;/code&gt;. In this phase, the JavaScript engine also assigns the actual values to already declared variables.&lt;/p&gt;

&lt;p&gt;Besides the Global Execution Context, there is &lt;strong&gt;Functional&lt;/strong&gt; Execution Context. In the next blog post, I will tell you more about Functional Execution Context and the differences between them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Recap
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Execution context&lt;/strong&gt; in JavaScript is a concept that describes the environment in which your code is currently running.&lt;/li&gt;
&lt;li&gt;Execution context has two phases:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Creation&lt;/strong&gt; and&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Execution&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;There are two execution contexts in JavaScript:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Global&lt;/strong&gt; and&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Functional&lt;/strong&gt; (or local)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;JavaScript engine creates &lt;strong&gt;Global Execution Context&lt;/strong&gt; once it runs JavaScript application.&lt;/li&gt;
&lt;li&gt;JavaScript creates two objects for us inside of Global Execution Context:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;global object&lt;/code&gt; and&lt;/li&gt;
&lt;li&gt;a variable, &lt;code&gt;this&lt;/code&gt; that, in the Browser, points to the same global object which is &lt;code&gt;window&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hoisting&lt;/strong&gt; is assigning a default value of &lt;code&gt;undefined&lt;/code&gt; to variable declarations in the &lt;code&gt;Creation&lt;/code&gt; phase.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>hoisting</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to set up nvm to work with fish shell?</title>
      <dc:creator>Zoran Stankovic</dc:creator>
      <pubDate>Tue, 23 Nov 2021 18:24:30 +0000</pubDate>
      <link>https://dev.to/ryunosukezoran/how-to-set-up-nvm-to-work-with-fish-shell-2bho</link>
      <guid>https://dev.to/ryunosukezoran/how-to-set-up-nvm-to-work-with-fish-shell-2bho</guid>
      <description>&lt;p&gt;Recently, I switched from oh-my-zsh to a &lt;a href="https://fishshell.com/"&gt;fish shell&lt;/a&gt;, and I didn’t regret it. Fish is a nice and user-friendly command-line shell. fish supports powerful features like syntax highlighting, autosuggestions, and tab completions that work, with nothing to learn or configure.&lt;br&gt;
But when I tried to install nvm (Node Version Manager) I had a problem, the shell didn’t recognize the nvm command. After some investigation, I found the solution.&lt;br&gt;
First, you need to install a &lt;a href="https://github.com/jorgebucaran/fisher"&gt;fisher&lt;/a&gt;. Fisher is a package manager for the fish shell. Download fisher.fish to your functions directory or any directory on your function path.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl https://git.io/fisher &lt;span class="nt"&gt;--create-dirs&lt;/span&gt; &lt;span class="nt"&gt;-sLo&lt;/span&gt; ~/.config/fish/functions/fisher.fish
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your shell can take a few seconds before loading newly added functions. If the fisher command is not immediately available, launch a new session or replace the running shell with a new one.&lt;br&gt;
After installing the fisher, you need to add the &lt;a href="https://github.com/edc/bass"&gt;Bass&lt;/a&gt; package. Bass makes it easy-to-use utilities written for Bash in a fish shell. Using fisher:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;fisher add edc/bass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create a new fish file for nvm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch&lt;/span&gt; ~/.config/fish/functions/nvm.fish
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And add fish function to it to load nvm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;function &lt;/span&gt;nvm
    bass &lt;span class="nb"&gt;source&lt;/span&gt; ~/.nvm/nvm.sh &lt;span class="nt"&gt;--&lt;/span&gt; no-use ‘&lt;span class="p"&gt;;&lt;/span&gt;’ nvm &lt;span class="nv"&gt;$argv&lt;/span&gt;
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And you are ready-to-use NVM.&lt;/p&gt;

&lt;h2&gt;
  
  
  How does NVM work?
&lt;/h2&gt;

&lt;p&gt;If you want to download, compile, and install the latest release of node you just need to do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvm &lt;span class="nb"&gt;install &lt;/span&gt;node &lt;span class="c"&gt;# “node” is an alias for the latest version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To install a specific version of node:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvm &lt;span class="nb"&gt;install &lt;/span&gt;10.10.0 &lt;span class="c"&gt;# or 8.9.1, etc.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Important to know is that the first version installed becomes the default. New shells start with the default version of node.&lt;br&gt;
To set a default Node version in any new shell, use the alias ‘default’:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nvm &lt;span class="nb"&gt;alias &lt;/span&gt;default &lt;span class="o"&gt;[&lt;/span&gt;version of node] &lt;span class="c"&gt;# e.g.&lt;/span&gt;
nvm &lt;span class="nb"&gt;alias &lt;/span&gt;default 12.13.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to use a specific version of NodeJS for your project, you can specify the NodeJS version inside of &lt;code&gt;.nvmrc&lt;/code&gt; file inside of your project e.g. &lt;code&gt;12.13.1&lt;/code&gt; and then activate it using &lt;code&gt;nvm use&lt;/code&gt; command in your shell.&lt;/p&gt;

</description>
      <category>shell</category>
      <category>fishshell</category>
      <category>terminal</category>
      <category>nvm</category>
    </item>
    <item>
      <title>My favorite image placeholder</title>
      <dc:creator>Zoran Stankovic</dc:creator>
      <pubDate>Mon, 22 Nov 2021 20:30:12 +0000</pubDate>
      <link>https://dev.to/ryunosukezoran/my-favorite-image-placeholder-4cfb</link>
      <guid>https://dev.to/ryunosukezoran/my-favorite-image-placeholder-4cfb</guid>
      <description>&lt;p&gt;For my first post, I decided to write about a tool that I always use gladly when mockup new websites. So here I would like to share with you my favorite image and video placeholder &lt;a href="http://placecorgi.com/"&gt;Place Corgi&lt;/a&gt;. As you can guess I am a Corgi lover and this image placeholder is just perfect for me, and everyone who loves dogs and especially Corgis.&lt;/p&gt;

&lt;p&gt;It is easy to use, just a link to Place Corgi site with a width and optional height specified after the URL.&lt;br&gt;
&lt;code&gt;http://placecorgi.com/width/height&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Also, we can place a video as a placeholder. To do that, we would add /v to the URL along with width and height&lt;br&gt;
&lt;code&gt;http://placecorgi.com/v/width/height&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can add the Place Corgi js file to your application, which will automatically replace any img tags that have the class corgi with images from Place Corgi.&lt;br&gt;
For this implementation visit site &lt;a href="http://placecorgi.com/"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>imageplaceholder</category>
      <category>html</category>
    </item>
  </channel>
</rss>
