<?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: A C E V E D O C</title>
    <description>The latest articles on DEV Community by A C E V E D O C (@theacevedoc).</description>
    <link>https://dev.to/theacevedoc</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%2F366208%2F416f3825-4dcb-48c7-a8ca-e8e1690d2d6b.jpg</url>
      <title>DEV Community: A C E V E D O C</title>
      <link>https://dev.to/theacevedoc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/theacevedoc"/>
    <language>en</language>
    <item>
      <title>Real JavaScript Interview questions</title>
      <dc:creator>A C E V E D O C</dc:creator>
      <pubDate>Tue, 09 Aug 2022 22:37:00 +0000</pubDate>
      <link>https://dev.to/theacevedoc/real-javascript-interview-questions-4433</link>
      <guid>https://dev.to/theacevedoc/real-javascript-interview-questions-4433</guid>
      <description>&lt;p&gt;Following are real questions asked to me in an interview. Of course there are many others concepts that can be asked. I hope this is useful for you guys.&lt;/p&gt;

&lt;p&gt;Questions are divided in two different sections:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Theory&lt;/li&gt;
&lt;li&gt;Code Snippets questions&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  1/2 Theory
&lt;/h2&gt;

&lt;h2&gt;
  
  
  What do you know about Primitive Data Types?
&lt;/h2&gt;

&lt;p&gt;It’s a type of data that represents a single value. That is, not an object. Following are the primitive data types in JavaScript:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;String&lt;/code&gt;: a sequence of characthers in ‘single’ or “double quotes”&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Number&lt;/code&gt;: integers or floating point number&lt;/p&gt;

&lt;p&gt;&lt;code&gt;boolean&lt;/code&gt;: only &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt; values&lt;/p&gt;

&lt;p&gt;&lt;code&gt;undefined&lt;/code&gt;: represents lack of existence, a variable that has not been assigned any value. As developer, you should &lt;strong&gt;never&lt;/strong&gt; set a variable to &lt;code&gt;undefined&lt;/code&gt; directly.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;null&lt;/code&gt; : also represents lack of existence. You can set a variable to &lt;code&gt;null&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What do you know about Objects?
&lt;/h2&gt;

&lt;p&gt;Objects are name value pairs that are sitting in memory and could be compound of properties and methods. The most common way to create an object is using &lt;em&gt;Object literal&lt;/em&gt; syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;lastname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Doe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;address&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;street&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;101 Sherman Ave&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;city&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;New York City&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;New York&lt;/span&gt;&lt;span class="dl"&gt;'&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;h2&gt;
  
  
  What is the &lt;code&gt;Object.prototype&lt;/code&gt; ?
&lt;/h2&gt;

&lt;p&gt;It is mechanish where you can find other methods inherited from other. For instance, when you create a new Date, you can find methods like &lt;code&gt;getYear()&lt;/code&gt; in this prototype chain.&lt;/p&gt;

&lt;h2&gt;
  
  
  What do you know about Arrays?
&lt;/h2&gt;

&lt;p&gt;Arrays are a type of object for storing collections in a single variable. Arrays can hold a mix of anything: functions, primitives, objects.&lt;/p&gt;

&lt;h2&gt;
  
  
  How does JavaScript works?
&lt;/h2&gt;

&lt;p&gt;Let’s take a look to following image and explain how Event Loop works:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DgMvCyno--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2hz7z61c1yr5vrohou9f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DgMvCyno--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2hz7z61c1yr5vrohou9f.png" alt="Event Loop image" width="880" height="682"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Call Stack (blue block):

&lt;ul&gt;
&lt;li&gt;It is the stack where all the code task will be stacking: Last In First Out. JavaScript can only execute one task at the time.&lt;/li&gt;
&lt;li&gt;Single tasks are executed but when we have other kind of tasks, like &lt;code&gt;setTimeOut&lt;/code&gt; , &lt;code&gt;setInterval&lt;/code&gt; or &lt;code&gt;fetch&lt;/code&gt; the Call Stack delegates it to the Web APIs.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Web APIs (purple block):

&lt;ul&gt;
&lt;li&gt;It is a set of tools that browsers make available. It is responsible for executing timers (for &lt;code&gt;setTimeOut&lt;/code&gt; or &lt;code&gt;setInterval&lt;/code&gt;) or trigger HTTP request for fetching data.&lt;/li&gt;
&lt;li&gt;Once the timer is completed or the HTTP request has a response, it will transfer the task to the Task Queue o Micro Task Queue.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Task Queue (yellow block):

&lt;ul&gt;
&lt;li&gt;It contains all the tasks pending to execution. Internally this tasks has a priority depending on what type they are. From high to low priority, tasks types could be: Render, DOM Tasks, UI Tasks, Net Tasks.&lt;/li&gt;
&lt;li&gt;Tasks on this queue are not executed. They are only waiting to be transfer by the Event Loop to Call Stack and there they will be executed.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Micro Tasks Queue (aqua block):

&lt;ul&gt;
&lt;li&gt;When a Promise has a response, either resolved or rejected, its tasks are moved to Micro Tasks Queue.&lt;/li&gt;
&lt;li&gt;Tasks on this queue are not executed. They are only waiting to be transfer by the Event Loop to Call Stack.&lt;/li&gt;
&lt;li&gt;Tasks on this queue has a &lt;strong&gt;higher priority&lt;/strong&gt; than tasks on the Task Queue, even if tasks on Tasks Queue are Render type.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Event Loop (green block):

&lt;ul&gt;
&lt;li&gt;It is a loop responsible for taking tasks from Tasks Queue/Micro Tasks Queue to Call Stack.&lt;/li&gt;
&lt;li&gt;It only transfers a task to the Call Stack, if the Call Stack is empty.&lt;/li&gt;
&lt;li&gt;If the Call Stack is empty, and there is one task in Micro Task Queue and another task in Task Queue, Event Loop will transfer first the task on the Micro Tasks due its priority. The remaining task will be moved once the Call Stack is empty again.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Differences between &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;let&lt;/code&gt;:

&lt;ul&gt;
&lt;li&gt;is block scope&lt;/li&gt;
&lt;li&gt;it can be updated&lt;/li&gt;
&lt;li&gt;it can be declared without initialization&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;const&lt;/code&gt;:

&lt;ul&gt;
&lt;li&gt;is block scope&lt;/li&gt;
&lt;li&gt;it cannot be updated&lt;/li&gt;
&lt;li&gt;it cannot be updated without initialization&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Differences between &lt;code&gt;map&lt;/code&gt; and &lt;code&gt;forEach&lt;/code&gt; ?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The main difference is that &lt;code&gt;map&lt;/code&gt; returns a new array by applying the callback function&lt;/li&gt;
&lt;li&gt;You can use &lt;code&gt;forEach&lt;/code&gt; just for iterate&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2/2 Code snippets
&lt;/h2&gt;

&lt;p&gt;If you execute following code, what does it will retrieve?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Response: &lt;code&gt;true&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Data type for Objects and Arrays is &lt;code&gt;object&lt;/code&gt; . Which means that the type of an empty object will be equals to the type of an&lt;/p&gt;




&lt;p&gt;If you execute following code, what name does it will console?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;user2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&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="s2"&gt;`user: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Response: It prints the user with name: &lt;code&gt;name2&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is because in JavaScript Primitive types are passed by Value and non Primitive types, like objects, are passed by Reference&lt;/p&gt;




&lt;p&gt;If you execute following code, what will be the output?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Lorem ipsum&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;promise1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;123&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;promise1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&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="s2"&gt;`Promise value: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Response:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello
Promise value
Lorem ipsum
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is related about we previously checked with the Event Loop. Tasks created as a response for a &lt;code&gt;Promise&lt;/code&gt; will be queue in the Micro Tasks Queue and they will have a higher priority than tasks on the Task Queue.&lt;/p&gt;




&lt;p&gt;I hope you find useful these questions if you are getting ready for an interview. And as always, the best luck!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>eventloop</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Hello, friend</title>
      <dc:creator>A C E V E D O C</dc:creator>
      <pubDate>Tue, 30 Mar 2021 03:35:42 +0000</pubDate>
      <link>https://dev.to/theacevedoc/hello-friend-567f</link>
      <guid>https://dev.to/theacevedoc/hello-friend-567f</guid>
      <description>&lt;p&gt;I know you are reading this. Just another developer writing on dev.to. I write about my experiences and some techie stuff.&lt;/p&gt;

&lt;p&gt;That's it, no big deal.&lt;/p&gt;

&lt;p&gt;Thank you for reading!&lt;/p&gt;

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