<?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: Taemin Kim</title>
    <description>The latest articles on DEV Community by Taemin Kim (@coder4je).</description>
    <link>https://dev.to/coder4je</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%2F892207%2Fd72f9896-88f6-4381-9dbc-44a0185427be.png</url>
      <title>DEV Community: Taemin Kim</title>
      <link>https://dev.to/coder4je</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/coder4je"/>
    <language>en</language>
    <item>
      <title>[JAVASCRIPT] Primitive vs. Reference Data Types</title>
      <dc:creator>Taemin Kim</dc:creator>
      <pubDate>Tue, 19 Jul 2022 00:16:49 +0000</pubDate>
      <link>https://dev.to/coder4je/javascript-primitive-vs-reference-data-types-3f6o</link>
      <guid>https://dev.to/coder4je/javascript-primitive-vs-reference-data-types-3f6o</guid>
      <description>&lt;h2&gt;
  
  
  In javascript, there are two different data type: primitive and reference
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Primitive Types&lt;/th&gt;
&lt;th&gt;Reference Types&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Number&lt;/td&gt;
&lt;td&gt;Object&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;String&lt;/td&gt;
&lt;td&gt;Array&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Boolean&lt;/td&gt;
&lt;td&gt;Function&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Null&lt;/td&gt;
&lt;td&gt;Map&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Undefined&lt;/td&gt;
&lt;td&gt;Set&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BigInt(ES6)&lt;/td&gt;
&lt;td&gt;WeakMap, WeakSet(ES6)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Symbol(ES6)&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Array, function, map, set, WeekMap, WeakSet are also objects.
&lt;/h3&gt;

&lt;h2&gt;
  
  
  Both types of variables have declaration and assignment.
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!-- Primitive Type --&amp;gt;
let name = "kevin";
let age = 20;

vs

&amp;lt;!-- Reference Type --&amp;gt;
let name = {name: "kevin", age: "20"};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Both types of variables are stored in memory at the declaration by using 'let'.
&lt;/h3&gt;

&lt;h3&gt;
  
  
  However, assignment works differently for the two variables.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xXk1Vw4n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j6stp8kb0ogjvfpbwe2y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xXk1Vw4n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j6stp8kb0ogjvfpbwe2y.png" alt="memory diagram" width="598" height="301"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  When variables are declared, their values are stored in either a 'stack' or a 'heap'. These memory types will not be covered in this article.
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;As you can see, the primitive types of variables, "Kevin" and 20 are stored in the stack as values when the reference variable of the object is stored as an address.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Key differences of the two types
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Primitive variables store primitive values&lt;/li&gt;
&lt;li&gt;Reference variables store an address&lt;/li&gt;
&lt;li&gt;The primitive's value is copied&lt;/li&gt;
&lt;li&gt;The reference's address is copied&lt;/li&gt;
&lt;li&gt;Primitive values are compared&lt;/li&gt;
&lt;li&gt;Reference addresses are compared&lt;/li&gt;
&lt;li&gt;The primitive value is returned&lt;/li&gt;
&lt;li&gt;The reference's address is returned&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  As you can see, data is categorized into two different types and the computer store them differently. It is important to understand and identify each type because it is common to face many issues related to the differences in these types.
&lt;/h3&gt;

&lt;h3&gt;
  
  
  I hope that you found this article helpful. Feel free to contact me for any questions or comments.
&lt;/h3&gt;

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