<?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: David Olaleye</title>
    <description>The latest articles on DEV Community by David Olaleye (@dev_dave).</description>
    <link>https://dev.to/dev_dave</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%2F914792%2F2e4b26ee-7380-45a9-9b5a-37fd9d2ece35.jpeg</url>
      <title>DEV Community: David Olaleye</title>
      <link>https://dev.to/dev_dave</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dev_dave"/>
    <language>en</language>
    <item>
      <title>How JavaScript Works Behind The Scenes Part 2</title>
      <dc:creator>David Olaleye</dc:creator>
      <pubDate>Thu, 08 Sep 2022 01:02:08 +0000</pubDate>
      <link>https://dev.to/dev_dave/how-javascript-works-behind-the-scenes-part-2-4m98</link>
      <guid>https://dev.to/dev_dave/how-javascript-works-behind-the-scenes-part-2-4m98</guid>
      <description>&lt;p&gt;👋 Hello guys! What if I told you &lt;code&gt;console.log()&lt;/code&gt; is not a part of JavaScript? 😲 or that &lt;code&gt;setTimeout()&lt;/code&gt; or &lt;code&gt;alert()&lt;/code&gt; aren't part of JavaScript as well? 🤯 I can see the gape in your mouth and the askance in your countenance at the moment which is understandable, that was how I felt as well when I initially realized it. &lt;/p&gt;

&lt;p&gt;This article is a sequel to &lt;a href="https://devdave.hashnode.dev/how-javascript-works-behind-the-scenes-part-1" rel="noopener noreferrer"&gt;part 1&lt;/a&gt;  of the workings of the JavaScript engine. &lt;/p&gt;

&lt;p&gt;We will be talking about the &lt;em&gt;non-blocking&lt;/em&gt; and the &lt;em&gt;asynchronous&lt;/em&gt; part of JavaScript, I mean we will be looking behind the scenes to see how JavaScript which is a &lt;em&gt;synchronous single-threaded language&lt;/em&gt; runs &lt;em&gt;asynchronous&lt;/em&gt; operations.   &lt;/p&gt;

&lt;p&gt;From the &lt;a href="https://devdave.hashnode.dev/how-javascript-works-behind-the-scenes-part-1" rel="noopener noreferrer"&gt;previous article&lt;/a&gt;, we saw how JavaScript runs our code in a synchronous manner from top to bottom. This is because JavaScript has only one call stack which it uses to execute the code. &lt;/p&gt;

&lt;p&gt;Imagine we had to load our tweets to the UI (user interface) in a synchronous manner, the JavaScript engine will read and parse the code line by line and when it gets to the line of the tweet request, the page will be non-responsive to clicks because we have to wait to get the data from an external source before other lines of code can resume execution. That doesn't seem like a very good user experience, right?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fflf7x0cv2mhoom8sout0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fflf7x0cv2mhoom8sout0.png" alt="javascript-run-time-environment" width="700" height="525"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The image above is a pictorial representation of the JavaScript run-time environment. From our previous article, we can identify the &lt;em&gt;Call Stack&lt;/em&gt; and the &lt;em&gt;Memory heap&lt;/em&gt; and their functions in running our code synchronously (line by line, top to bottom). The other parts are the:&lt;/p&gt;

&lt;h3&gt;
  
  
  Web APIs
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Callback Queue
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Event Loop
&lt;/h3&gt;

&lt;p&gt;We will run a short example below by simulating an asynchronous code execution with the &lt;code&gt;setTimeout()&lt;/code&gt; function.&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("first");

console.log("second");

function printName() {
    console.log("My name is David");
}

setTimeout(printName, 2000);

console.log("End of the program");

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

&lt;/div&gt;



&lt;p&gt;Judging by our synchronous programming knowledge, in what order do you think the code above will be executed?&lt;/p&gt;

&lt;p&gt;let's take this step by step.&lt;/p&gt;

&lt;p&gt;first of we are in the Global Execution Context (window environment), and our code will be read from top to bottom in order to allocate memory to variables and function bodies in the &lt;em&gt;Memory Allocation Phase&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;&lt;code&gt;function printName() {....}&lt;/code&gt; would be stored in a &lt;em&gt;key: value&lt;/em&gt; pair with the function name &lt;em&gt;printName&lt;/em&gt; as the key and &lt;em&gt;undefined&lt;/em&gt; as the value. Now the Code Execution phase. &lt;code&gt;console.log("first")&lt;/code&gt; being a function invocation will be pushed on the Call stack and a &lt;em&gt;Functional Execution Context&lt;/em&gt; will be created.&lt;/p&gt;

&lt;p&gt;The string value &lt;em&gt;first&lt;/em&gt; would be logged to the screen, the console would be popped off the Call stack, and that function execution context would be gone. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;console.log("second")&lt;/code&gt; would go through the same process of getting pushed to the Call stack and also creating a &lt;em&gt;Functional Execution Context&lt;/em&gt; and log the string value &lt;em&gt;second&lt;/em&gt; to the screen, the function will be popped off the call stack and the function execution context gone.&lt;/p&gt;

&lt;p&gt;We will skip the &lt;code&gt;function printName() {....}&lt;/code&gt; line because it hasn't been invoked and we do not have access to the gate &lt;code&gt;{ }&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now something interesting is happening, we have a &lt;code&gt;setTimeout()&lt;/code&gt; function with a &lt;em&gt;callback function&lt;/em&gt; and a &lt;em&gt;timer&lt;/em&gt; inside of it.&lt;/p&gt;

&lt;p&gt;from our rudimentary knowledge of the JavaScript engine and how it works, we know that the JavaScript engine does not have a timer attached to it, which means that the JavaScript engine itself is not equipped to schedule the execution of operations. &lt;/p&gt;

&lt;p&gt;This is where the &lt;strong&gt;Web APIs&lt;/strong&gt;, &lt;strong&gt;Callback queue&lt;/strong&gt;, and the &lt;strong&gt;Event loop&lt;/strong&gt; comes in. Now back to the first statement of this article, &lt;code&gt;console.log()&lt;/code&gt;, &lt;code&gt;setTimeout()&lt;/code&gt; are part of the Web API that helps us in executing asynchronous operations in JavaScript&lt;/p&gt;

&lt;p&gt;This makes up the &lt;em&gt;JavaScript run-time environment&lt;/em&gt; in the Web API, we have a timer that helps in scheduling executions of function that is measured in &lt;em&gt;milliseconds&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;So &lt;code&gt;setTimeout(printName, 2000)&lt;/code&gt; means execute the &lt;code&gt;printName&lt;/code&gt; function in 2000 miliseconds (2 seconds) BUT continue running the other code in our program. &lt;/p&gt;

&lt;p&gt;This is where the &lt;strong&gt;non-blocking&lt;/strong&gt; part comes in. Take 2 seconds to store the &lt;code&gt;printName&lt;/code&gt; function in the Web API land but in the meantime, &lt;strong&gt;DO NOT BLOCK THE THREAD OF EXECUTION&lt;/strong&gt; in our program because JavaScript doesn't wait for anyone.&lt;/p&gt;

&lt;p&gt;So the question now is &lt;em&gt;where is &lt;code&gt;printName()&lt;/code&gt; sent off to? and how do we get our result back into the *JavaScript land&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Hence the behavior below&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqfs4oly1wk07f1j7n98c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqfs4oly1wk07f1j7n98c.png" alt="async-setTimeout-example-2" width="800" height="413"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;setTimeout()&lt;/code&gt; itself being a function is also pushed to the Call stack and a function execution context is created but it's immediately shipped to the Web API environment with the &lt;em&gt;timer&lt;/em&gt; attached to it, meanwhile, our code continues to run in JavaScript land nonetheless. Immediately after the timer is exhausted, the function &lt;code&gt;printName&lt;/code&gt; is pushed onto the &lt;strong&gt;Callback queue&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Callback queue&lt;/strong&gt; unlike the &lt;strong&gt;Call stack&lt;/strong&gt; has a data structure of FIFO &lt;em&gt;First in First out&lt;/em&gt;. It is a queue, just like a conventional queue at the store, it's on a first-come, first-served basis. &lt;/p&gt;

&lt;p&gt;So function &lt;code&gt;printName&lt;/code&gt; is queued for execution in the  Web API land (callback queue) looking to get back into JavaScript land. So how does this transition occur?&lt;/p&gt;

&lt;p&gt;This is where the &lt;strong&gt;Event Loop&lt;/strong&gt; comes into action to save the day. The loop has only one job and this job is to monitor the call stack to see if there is any function waiting to be executed.&lt;/p&gt;

&lt;p&gt;Let's say we had 100 lines of code after our &lt;code&gt;setTimeout()&lt;/code&gt; function, as long as they are synchronous, JavaScript will keep executing them allocating memory, pushing to the call stack, and creating functional execution context (which is its major job).&lt;/p&gt;

&lt;p&gt;Immediately after the call stack is empty, the &lt;strong&gt;Event loop&lt;/strong&gt; will keep monitoring to check if we have any function in the call stack and if we have any function in the callback queue, if the stack is empty, the function in the queue will be pushed to the call stack.&lt;/p&gt;

&lt;p&gt;Which in our case is the function &lt;code&gt;printName&lt;/code&gt; and we will go through the same process of creating a functional execution contest and then log the string value &lt;code&gt;My name is David&lt;/code&gt; to the console. Which explains the behavior above. &lt;/p&gt;

&lt;p&gt;Now you might ask, &lt;em&gt;What if we set our timer to 0?&lt;/em&gt;, will it change the behavior of our code? let's see that in action.&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("first");

console.log("second");

function printName() {
    console.log("My name is David");
}

setTimeout(printName, 0);

console.log("End of the program");

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3fs38mrfmmcgzjpl8a3g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3fs38mrfmmcgzjpl8a3g.png" alt="async-setTimeout-example2" width="800" height="415"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Voila! It doesn't matter, right? we will still go through the same &lt;em&gt;Web API&lt;/em&gt; --&amp;gt; &lt;em&gt;callback queue&lt;/em&gt; --&amp;gt; &lt;em&gt;event loop&lt;/em&gt; --&amp;gt; &lt;em&gt;call stack&lt;/em&gt; process, only this time with 0 milliseconds timer in the web API land. So if we had hundreds or thousands of lines of synchronous code to run, JavaScript will wait for no one until it's done with its tasks.&lt;/p&gt;

&lt;p&gt;I know this can be a lot to take in, it took me a while as well. I do hope you've got some introductory insight 💡 into how &lt;strong&gt;JavaScript is a synchronous single-threaded language that can be non-blocking&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Thank you for your time, and good luck in your journey. Remember, &lt;em&gt;it is a marathon and not a sprint&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;I will appreciate your feedback through &lt;a href="https://twitter.com/SIRchievous/" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; &lt;br&gt;
 &lt;a href="https://github.com/Pisces2802" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; &lt;a href="https://www.linkedin.com/in/david-olaleye-960435166/" rel="noopener noreferrer"&gt;linkedin&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How Javascript Works Behind The Scenes part 1</title>
      <dc:creator>David Olaleye</dc:creator>
      <pubDate>Thu, 01 Sep 2022 08:34:06 +0000</pubDate>
      <link>https://dev.to/dev_dave/how-javascript-works-behind-the-scenes-part-1-206f</link>
      <guid>https://dev.to/dev_dave/how-javascript-works-behind-the-scenes-part-1-206f</guid>
      <description>&lt;h3&gt;
  
  
  Javascript  Is  A  Synchronous
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Single-Threaded  Language
&lt;/h3&gt;

&lt;h3&gt;
  
  
  That  Can  Be  Non-Blocking.
&lt;/h3&gt;

&lt;p&gt;👋 This is the first part of an introductory article on how Javascript executes our code behind the scenes. If you have been familiar with javascript for a while (or not), you would most likely have come across the statement above and if you haven't, consider yourself informed 😎. &lt;/p&gt;

&lt;p&gt;Personally, it took me a while to wrap my head around the &lt;em&gt;single-threaded&lt;/em&gt; and &lt;em&gt;non-blocking&lt;/em&gt; concept of Javascript as a programming language 😕. To fully understand how codes are being executed, you need to understand how Javascript was designed to run. &lt;/p&gt;

&lt;p&gt;This will greatly help in fixing bugs, writing cleaner and easy-to-understand code, and also help new developers in their development journey. I will try as much as possible to simplify the concepts in this article to be easily understood. You might need to refer to it over again for it to stick, all you need is a heart willing to learn and a smile on your face 🙂&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a program?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A program has to do 2 things.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Allocate Memory&lt;/li&gt;
&lt;li&gt;Parse and Execute&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Allocate memory&lt;/em&gt; : This means that a program should be able to store values as variables.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Parse and execute&lt;/em&gt;: A program should be able to run commands passed to it, this includes executing functions and other operations based on the values in the memory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function printValue(a) {
    console.log(a);
}
printValue(variable) // value
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Javascript can effectively run these operations because of the Javascript engine, and in the Google Chrome browser, it's called the &lt;strong&gt;V8 engine&lt;/strong&gt;. The &lt;strong&gt;V8&lt;/strong&gt; engine reads the code we write and changes it to machine-executable instructions for the browser which then adds functionality to our page. &lt;/p&gt;

&lt;p&gt;The Javascript engine has 2 major parts which are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Memory Heap&lt;/li&gt;
&lt;li&gt;Call Stack&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Memory heap&lt;/em&gt;: This is where the memory allocation occurs.&lt;br&gt;
&lt;em&gt;Call stack&lt;/em&gt;: This is where our codes are executed and it also shows where we are in the program.  &lt;/p&gt;

&lt;p&gt;Javascript being a single-threaded language simply means it has just one Call stack used in executing the instructions in the program. The Call stack has a FILO &lt;em&gt;First in Last Out&lt;/em&gt; structure of execution. Since Javascript is single-threaded, it means it reads our code line by line in a specific order (from top to bottom).&lt;/p&gt;

&lt;p&gt;If you have had some experience with javascript you might begin to wonder &lt;em&gt;If Javascript is a synchronous single-threaded language, how then do we perform asynchronous operations?&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;Though that's presently out of the scope of this part, performing asynchronous operations is possible due to the web API that's part of the browser which makes up the &lt;strong&gt;Javascript Run-Time Environment&lt;/strong&gt;. We will talk more about this in the sequel. &lt;/p&gt;

&lt;p&gt;Every execution of code in Javascript occurs in an &lt;strong&gt;Execution Context&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Global Execution Context (window)&lt;/li&gt;
&lt;li&gt;The Functional Execution Context.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;The Global Execution Context&lt;/em&gt; is the first context that is created immediately after the page is loaded even before any line of code is run.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var name = "David";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the variable &lt;code&gt;name&lt;/code&gt; is parsed and stored on the window Object in &lt;em&gt;key: value&lt;/em&gt; pair.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feoksm8nqmb9h4h3r595k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feoksm8nqmb9h4h3r595k.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgwtclabeekito37lp8vk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgwtclabeekito37lp8vk.png" alt=" " width="800" height="415"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;name&lt;/code&gt; is added to the window Object&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function myName() {
    alert("My name is David");
}

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd3rvmu9c2kh7sodus6sc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd3rvmu9c2kh7sodus6sc.png" alt=" " width="800" height="431"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F659tlrim5dpoy40iser3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F659tlrim5dpoy40iser3.png" alt=" " width="800" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;we can also see that &lt;code&gt;function name&lt;/code&gt; is on the window object in a &lt;em&gt;key: value&lt;/em&gt; pair.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The Functional Execution Contest&lt;/em&gt; is only created when a function is invoked or called by &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; function myName() {
    debugger;
   var name = "David";
    alert(`My name is ${name}`)
}

myName(); //My name is David
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By putting a &lt;code&gt;debugger&lt;/code&gt; in our function body, we're able to pause the function execution and step over at will to see the &lt;code&gt;local&lt;/code&gt; section and the &lt;em&gt;Call stack&lt;/em&gt; in our browser. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;name&lt;/code&gt; is a local variable to the function &lt;code&gt;myName&lt;/code&gt; and it won't be on the Global Execution Context which is the &lt;strong&gt;Window&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvvog5vsgohy964trnzi0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvvog5vsgohy964trnzi0.png" alt=" " width="800" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can see in the highlighted part that immediately after the &lt;code&gt;myName&lt;/code&gt; function was invoked, the function was pushed on the &lt;em&gt;Call Stack&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flw9debepmre4g2cq0z3n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flw9debepmre4g2cq0z3n.png" alt=" " width="800" height="435"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And after the invocation of the &lt;code&gt;myName()&lt;/code&gt; function, it is &lt;em&gt;popped&lt;/em&gt; off the call stack.&lt;/p&gt;

&lt;p&gt;Javascript code execution happens in 2 phases, the &lt;strong&gt;Memory Allocation phase&lt;/strong&gt; and the &lt;strong&gt;Code Execution Phase&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We will take another example for better understanding.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var number = 5;

function multiply(num) {
    var result = num * num;
    return result;
}

var multiplied = multiply(number); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Memory Allocation Phase&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first thing that Javascript does is to allocate memory to all the variables and functions on the page ie it reads the page from the top to the bottom (depending on the Execution Context the thread of execution is).&lt;/p&gt;

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

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Memory&lt;/th&gt;
&lt;th&gt;Thread of Execution&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;number: undefined&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;multiply: { ...function }&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;multiplied: undefined&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The first line is &lt;code&gt;var number = 5&lt;/code&gt; number is stored as a &lt;em&gt;key&lt;/em&gt; and a special placeholder &lt;code&gt;undefined&lt;/code&gt; is appended as the &lt;em&gt;value&lt;/em&gt; in this first phase.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the second line, we have &lt;code&gt;function multiply () {}&lt;/code&gt; the whole function body is stored also as a &lt;em&gt;key: value&lt;/em&gt; pair. The &lt;em&gt;key&lt;/em&gt; is the function name &lt;code&gt;multiply&lt;/code&gt; and the &lt;em&gt;value&lt;/em&gt; is the whole function body. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Always remember that only a &lt;strong&gt;function invocation&lt;/strong&gt; or a &lt;strong&gt;function call&lt;/strong&gt; can allow Javascript to enter a function. Have a mental image that the curly braces &lt;code&gt;{ }&lt;/code&gt; is a gate to the function body and an invocation is a key to the function. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The third line is also a variable and will be stored as a &lt;em&gt;key: value&lt;/em&gt; pair with the variable name &lt;code&gt;multiplied&lt;/code&gt; as the &lt;em&gt;key&lt;/em&gt; and &lt;code&gt;undefined&lt;/code&gt; as the value.&lt;br&gt;
Note that we are in the &lt;em&gt;Global Execution Context&lt;/em&gt; during this phase.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Code Execution Phase&lt;/strong&gt;&lt;br&gt;
In this phase, this is when Javascript allocates the values to the variables and also invokes functions that create a new &lt;em&gt;Executional Context&lt;/em&gt; and perform specific operations in our code base. The code is also read from top to bottom. &lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Memory&lt;/th&gt;
&lt;th&gt;Thread of Execution&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;number: 5&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;multiplied: multiply()&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Our code is read again from top to bottom, &lt;code&gt;5&lt;/code&gt; is appended to &lt;code&gt;var number&lt;/code&gt; as the &lt;em&gt;value&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The second line is skipped because we can't enter the function body because it hasn't been called yet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now this is where the magic happens, there is a function invocation in the next line &lt;code&gt;var multiplied = multiply(number)&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Any time we see the parenthesis &lt;code&gt;()&lt;/code&gt; in Javascript, two major things happen. &lt;/p&gt;

&lt;p&gt;1 A Functional Execution Context is created.&lt;br&gt;
2 The function is pushed unto the Call Stack.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Multiply()&lt;/code&gt; being a function invocation then creates a new &lt;em&gt;Functional Execution Context&lt;/em&gt; and then we repeat the same process of&lt;br&gt;
&lt;em&gt;Memory Allocation&lt;/em&gt; and &lt;em&gt;Code Execution&lt;/em&gt; reading from top to bottom. &lt;/p&gt;

&lt;h4&gt;
  
  
  Functional Execution Context
&lt;/h4&gt;

&lt;p&gt;In this phase, we will only be concerned with the content of the &lt;code&gt;function multiply() {}&lt;/code&gt; because the invocation &lt;code&gt;multiply()&lt;/code&gt; has now given us access through the gates &lt;code&gt;{ }&lt;/code&gt; into the function body. &lt;/p&gt;

&lt;p&gt;As we know by now we have the &lt;em&gt;Memory Allocation Phase&lt;/em&gt; where memory is allocated to the variables and functions inside the &lt;code&gt;multiply&lt;/code&gt; function, this also includes the &lt;em&gt;parameter&lt;/em&gt; &lt;code&gt;num&lt;/code&gt; because it is local to the &lt;code&gt;multiply&lt;/code&gt; function. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Memory Allocation Phase&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Memory&lt;/th&gt;
&lt;th&gt;Thread of Execution&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;num: undefined&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;result: undefined&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;undefined&lt;/code&gt; is appended as a placeholder for variable &lt;code&gt;num&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;undefined&lt;/code&gt; is appended as a placeholder for variable &lt;code&gt;result&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Code Execution Phase&lt;/strong&gt;&lt;br&gt;
We will be repeating the process of reading the lines of code from top to bottom in the &lt;code&gt;function multiply&lt;/code&gt; and executing them.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Memory&lt;/th&gt;
&lt;th&gt;Thread of Execution&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;num: 5&lt;/td&gt;
&lt;td&gt;5 * 5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;result: 25&lt;/td&gt;
&lt;td&gt;= 25&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;num&lt;/code&gt; which is a &lt;em&gt;parameter&lt;/em&gt; local to the &lt;code&gt;function multiply&lt;/code&gt; is allocated with the value of &lt;code&gt;5&lt;/code&gt; which is passed as an &lt;em&gt;argument&lt;/em&gt; to the function invocation &lt;code&gt;multiply(number)&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;number&lt;/code&gt; is the variable that was stored in &lt;em&gt;Global memory&lt;/em&gt; on the windows object. &lt;code&gt;number&lt;/code&gt; is the argument that was substituted for &lt;code&gt;num&lt;/code&gt; as the parameter.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The local variable &lt;code&gt;result&lt;/code&gt; stores the evaluated value  of &lt;code&gt;num * num&lt;/code&gt; which is &lt;code&gt;5 * 5 = 25&lt;/code&gt; in the &lt;em&gt;Functional Execution Contest&lt;/em&gt; (local memory).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The keyword &lt;code&gt;return&lt;/code&gt; being the last line in the &lt;code&gt;function multiply&lt;/code&gt; body does something very interesting. &lt;/p&gt;

&lt;p&gt;It simply means returning the result of the computation in that function body to the Execution Context where the function was invoked which in our case is the &lt;em&gt;Global Execution Context&lt;/em&gt; where variable &lt;code&gt;multiplied&lt;/code&gt; was stored in memory. &lt;/p&gt;

&lt;p&gt;The value &lt;code&gt;25&lt;/code&gt; would now be replaced with the placeholder &lt;code&gt;undefined&lt;/code&gt;. so &lt;code&gt;var multiplied = 25&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When Javascript encounters the &lt;code&gt;return&lt;/code&gt; keyword in the &lt;em&gt;code Execution Phase&lt;/em&gt; of our program,&lt;/p&gt;

&lt;p&gt;1 The &lt;em&gt;Execution Context&lt;/em&gt; is deleted. &lt;/p&gt;

&lt;p&gt;2 The function is popped off the &lt;em&gt;Call Stack&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;3 The control of that function with its result (which can be of any data type including a function) is transferred to the &lt;em&gt;Execution Context&lt;/em&gt; where the function was invoked. &lt;/p&gt;

&lt;p&gt;In our case, it was to the variable &lt;code&gt;multiplied&lt;/code&gt; in the  &lt;em&gt;Global Execution Context&lt;/em&gt; other times, it could be to another &lt;em&gt;Functional Executional Context&lt;/em&gt; depending on how deep into the program we are.&lt;/p&gt;

&lt;p&gt;I know this is a lot to take in, but it gets easier after a while, just make sure you reference this article as often as you can. In the subsequent text, we will be looking at the &lt;strong&gt;non-blocking&lt;/strong&gt; part of Javascript. &lt;/p&gt;

&lt;p&gt;For us to vividly get the picture, we need to understand the other parts of the Javascript run-time environment that makes asynchronous programming possible.&lt;/p&gt;

&lt;p&gt;I do hope you have at least gained some basic insight into how Javascript executes our code, Thank you for your time, and good luck in your journey. Remember, &lt;em&gt;it is a marathon and not a sprint&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;I will appreciate your feedback through &lt;a href="https://twitter.com/SIRchievous/" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; &lt;br&gt;
 &lt;a href="https://github.com/Pisces2802" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>functionalcontext</category>
      <category>globalexecutioncontext</category>
    </item>
    <item>
      <title>Introduction to Data Types in Javascript</title>
      <dc:creator>David Olaleye</dc:creator>
      <pubDate>Wed, 24 Aug 2022 17:33:00 +0000</pubDate>
      <link>https://dev.to/dev_dave/introduction-to-data-types-in-javascript-2pb8</link>
      <guid>https://dev.to/dev_dave/introduction-to-data-types-in-javascript-2pb8</guid>
      <description>&lt;p&gt;In every generic human language, there are parts of speech and rules that guide the usage of such. In the English Language, for example, we have parts of speech like &lt;em&gt;Nouns&lt;/em&gt;, &lt;em&gt;Pronouns&lt;/em&gt;, &lt;em&gt;Verbs&lt;/em&gt;, &lt;em&gt;Adjectives&lt;/em&gt;, etc. The English Language as a human language is used for communication, while &lt;strong&gt;Javascript as a higher level programming language is used to add functionality to web pages&lt;/strong&gt; ie &lt;em&gt;It makes user interaction with the web page possible&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;In This article, I will be going over the major Data Types in Javascript which can also be referred to as &lt;strong&gt;values&lt;/strong&gt;.&lt;br&gt;
This write-up is beginner friendly and an introductory insight to data types for anyone new to the Javascript world. Below are the 7 major Data Types in Javascript.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Number&lt;/li&gt;
&lt;li&gt;Bigint&lt;/li&gt;
&lt;li&gt;String&lt;/li&gt;
&lt;li&gt;Boolean (logical type)&lt;/li&gt;
&lt;li&gt;null&lt;/li&gt;
&lt;li&gt;Object&lt;/li&gt;
&lt;li&gt;undefined&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Number
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;number&lt;/strong&gt; data type is like a generic number we are all familiar with for basic arithmetic operations like multiplication &lt;code&gt;*&lt;/code&gt;, division &lt;code&gt;/&lt;/code&gt;, addition &lt;code&gt;+&lt;/code&gt;, and subtraction &lt;code&gt;-&lt;/code&gt;. &lt;em&gt;Number&lt;/em&gt; can either be &lt;strong&gt;floating point number&lt;/strong&gt; (decimals) or &lt;strong&gt;integer&lt;/strong&gt; (whole numbers)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let number = 5;
let floatingNumber = 1.234;

let addition = 5 + 5;
console.log(addition) //10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;we can perform any arithmetic operation on numbers and have their results stored in a variable to be used anywhere else in our code base.&lt;br&gt;
Aside from conventional numbers, we have 3 unique numerical values which are&lt;br&gt;
&lt;code&gt;infinity&lt;/code&gt;, &lt;code&gt;-infinity&lt;/code&gt;, &lt;code&gt;NaN&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;infinity&lt;/code&gt; results when we divide a number by 0 which is greater than any numeric value
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(1 / 0) //infinity
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;NaN&lt;/code&gt; This stands for &lt;em&gt;not a number&lt;/em&gt; it results when you try to perform an incorrect arithmetic operation. for example when we try to divide a &lt;em&gt;string&lt;/em&gt; with a &lt;em&gt;number&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log("word"/5) //NaN
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Bigint
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Bigint&lt;/strong&gt; is a way to represent whole numbers in computer programming that are larger than &lt;strong&gt;253-1&lt;/strong&gt; or &lt;strong&gt;-(253-1)&lt;/strong&gt; for negatives.&lt;br&gt;
integers greater than &lt;strong&gt;253-1&lt;/strong&gt; can not be stored in the &lt;em&gt;number&lt;/em&gt; type so Bigint was created to accommodate this change to numbers with unconventional lengths.&lt;/p&gt;

&lt;p&gt;A &lt;em&gt;Bigint&lt;/em&gt; value is added by appending &lt;code&gt;n&lt;/code&gt; to the end of the integer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const bigInt = 1234567890123456789012345678901234567890n;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you might begin to wonder about the practicality of applying the Bigint value in the wild, though it's not regularly used and you may never encounter them in a code base but they can be used for cryptography or microsecond-precision timestamps which are outside the scope of this tutorial.&lt;/p&gt;

&lt;h2&gt;
  
  
  String
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;String&lt;/strong&gt; are basically characters in javascript, just like a string of alphabets makes up a word in the English Language, a string is a combination of characters, although for beginners the name sounds counter-intuitive, always remember that &lt;em&gt;strings&lt;/em&gt; in Javascript are characters. A &lt;em&gt;string&lt;/em&gt; can also be empty &lt;code&gt;" "&lt;/code&gt; or &lt;code&gt;''&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;string&lt;/em&gt; can be denoted in 3 different ways.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let string1 = "javascript"; //double quotes
let string2 = 'javascript'; //single quotes
let string3 = `javascript`; //backticks
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;backticks&lt;/em&gt; are really powerful in javascript because it allows us to interpolate values, by wrapping them in &lt;br&gt;
&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 name = "David";
let phrase = `My name is ${name}`
console.log(phrase) //My name is David

console.log(`The sum is ${1 + 2 }`) //The sum is 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is basically no functional difference between the &lt;em&gt;single quotes&lt;/em&gt; &lt;code&gt;' '&lt;/code&gt; and the &lt;em&gt;double quotes&lt;/em&gt; &lt;code&gt;" "&lt;/code&gt; it all boils down to personal preference and style.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Boolean (logical type)
&lt;/h2&gt;

&lt;p&gt;A javascript &lt;em&gt;boolean&lt;/em&gt; represents either one of two values. &lt;strong&gt;true&lt;/strong&gt; or &lt;strong&gt;false&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;true&lt;/strong&gt; resulting in &lt;em&gt;yes&lt;/em&gt;&lt;br&gt;
&lt;strong&gt;false&lt;/strong&gt; resulting in &lt;em&gt;no&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;boolean&lt;/strong&gt; values are very effective in toggling eg &lt;em&gt;turning a switch on or off&lt;/em&gt;, &lt;em&gt;displaying a drop-down or a hamburger icon or not&lt;/em&gt;&lt;br&gt;
Note that everything with a value results in &lt;em&gt;true&lt;/em&gt; and &lt;em&gt;false&lt;/em&gt; if there is no value.&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(5 &amp;gt; 4) //true

let isNameAString = true;
console.log(isNameAString); //true

let isUserValid = false;
console.log(isUserValid) //false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;values can also be set to either &lt;em&gt;true&lt;/em&gt; or &lt;em&gt;false&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Null
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Null&lt;/strong&gt; is a special value in Javascript that denotes &lt;em&gt;empty&lt;/em&gt;, &lt;em&gt;nothing&lt;/em&gt;, &lt;em&gt;unknown value&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 name = null;
console.log(name) //null
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;name&lt;/code&gt; is intentionally absent, &lt;em&gt;null&lt;/em&gt; is the intentional absence of any value.&lt;/p&gt;

&lt;h2&gt;
  
  
  Objects
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Objects&lt;/strong&gt; are special data types in Javascript that are used for storing the collection of values (which can be of any data type) in a &lt;code&gt;{key: value}&lt;/code&gt; pair. &lt;em&gt;keys&lt;/em&gt; in objects can also be referred to as &lt;em&gt;properties&lt;/em&gt;. In javascript, other data types are called &lt;em&gt;primitive values&lt;/em&gt;, while objects are referred to as &lt;em&gt;reference values&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 human1 = {
    firstName: "David",
    lastName: "Olaleye",
    isAnEngineer: true,
    legs: 2,
    children: null
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code above is an example of an &lt;em&gt;object literal&lt;/em&gt; syntax. Objects are very complex data types and going deeper is outside of the scope of this tutorial. An object is one of the major building blocks of &lt;strong&gt;Object Oriented Programming&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Object properties can also be assigned.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;human1.firstName = "Mike"
console.log(human1.firstName) //Mike
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, we set the &lt;code&gt;firstName&lt;/code&gt; property of the human1 object from string&lt;code&gt;"David"&lt;/code&gt; to the string &lt;code&gt;"Mike"&lt;/code&gt; using the &lt;strong&gt;. notation&lt;/strong&gt;. This can also be done with the &lt;em&gt;square bracket notation&lt;/em&gt; below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;human1["firstName"] = "Ed";
console.log(human1["firstName"]) //Ed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Undefined
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;undefined&lt;/strong&gt; is another special data type in javascript that denotes that a value is not assigned.&lt;br&gt;
In javascript, a value can be declared and assigned later.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let name;
console.log(name); //undefined 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The name variable above was declared but not assigned with a value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name = "David"
console.log(name) //David
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The name variable above has been assigned a &lt;em&gt;string&lt;/em&gt; value &lt;code&gt;"David"&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Note:
&lt;/h3&gt;

&lt;p&gt;We can assign &lt;code&gt;null&lt;/code&gt; to a value if it is &lt;em&gt;unknown&lt;/em&gt; or &lt;em&gt;empty&lt;/em&gt; but it is not advisable to assign &lt;code&gt;undefined&lt;/code&gt;&lt;br&gt;
to a value explicitly. &lt;em&gt;undefined&lt;/em&gt; is specially reserved for unassigned values as a default. &lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;In this article we covered the major data types we have in javascript. Although this is meant to be beginner friendly, as you go on in your web development career, you will begin to learn about these data types in depth (caveat, trade-offs, and best practices). I do hope you have gotten some sort of introductory insight in this article, Thank you for your time, and good luck in your journey. Remember, &lt;em&gt;it is a marathon and not a sprint&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;I will appreciate your feedback through &lt;a href="https://twitter.com/SIRchievous/" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; &lt;br&gt;
 &lt;a href="https://github.com/Pisces2802" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; &lt;a href="https://www.linkedin.com/in/david-olaleye-960435166/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
