<?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: Edward Luu</title>
    <description>The latest articles on DEV Community by Edward Luu (@edwardluu).</description>
    <link>https://dev.to/edwardluu</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%2F388351%2Fcd1ecf80-5a3f-42e1-8588-449f0d6314f6.jpeg</url>
      <title>DEV Community: Edward Luu</title>
      <link>https://dev.to/edwardluu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/edwardluu"/>
    <language>en</language>
    <item>
      <title>Understanding to Hoisting</title>
      <dc:creator>Edward Luu</dc:creator>
      <pubDate>Tue, 17 Nov 2020 04:11:46 +0000</pubDate>
      <link>https://dev.to/edwardluu/understanding-to-hoisting-4ll4</link>
      <guid>https://dev.to/edwardluu/understanding-to-hoisting-4ll4</guid>
      <description>&lt;h2&gt;
  
  
  What is Hoisting?
&lt;/h2&gt;

&lt;p&gt;Hoisting is JavaScript's default behavior of moving all declarations to the top of the current scope (to the top of the current script or the current function).&lt;/p&gt;

&lt;h2&gt;
  
  
  Variable
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Example of hoisting
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(A); // Returns undefined, as the only declaration was hoisted, no initialization has happened at this stage 

var A = 'edward';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explain for this one, the declare of &lt;code&gt;A&lt;/code&gt; will push to the top of the current scope. But the value of &lt;code&gt;A&lt;/code&gt; does not assign for now. See the code below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var A; // Declaration
console.log(A); //Returns undefined, as only declaration was hoisted, no initialization has happened at this stage 
A = 'edward'; // Initialization
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  The let and const Keywords
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Variables defined with &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; are hoisted to the top of the block, but not initialized.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Meaning: The block of code is aware of the variable, but it cannot be used until it has been declared.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using a let or const variable before it is declared will result in a &lt;code&gt;ReferenceError&lt;/code&gt;.&lt;br&gt;
&lt;/p&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(A); // Uncaught ReferenceError: Cannot access 'A' before initialization

let A = 'edward';

//const similar to let.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Function
&lt;/h2&gt;

&lt;p&gt;One of the advantages of JavaScript putting function declarations into memory before it executes any code segment is that it allows you to use a function before you declare it in your code. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;displayName('Edward'); // My name is Edward 

function displayName(name) {
  console.log(`My name is ${name}`);
}

let displayName1 = displayName('Edward');
let displayName2 = new displayName('Edward');

console.log(displayName1) //underfined
console.log(displayName2) // {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even though we call the function in our code first, before the function is written, the code still works. This is because of how context execution works in JavaScript.&lt;/p&gt;

&lt;p&gt;Reference :&lt;br&gt;
&lt;a href="https://www.w3schools.com/js/js_hoisting.asp"&gt;https://www.w3schools.com/js/js_hoisting.asp&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Hoisting"&gt;https://developer.mozilla.org/en-US/docs/Glossary/Hoisting&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Understanding to Closures </title>
      <dc:creator>Edward Luu</dc:creator>
      <pubDate>Tue, 10 Nov 2020 04:20:08 +0000</pubDate>
      <link>https://dev.to/edwardluu/understanding-to-closures-4oee</link>
      <guid>https://dev.to/edwardluu/understanding-to-closures-4oee</guid>
      <description>&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbsjpgnd67x3or47j198e.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbsjpgnd67x3or47j198e.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What is this?
&lt;/h3&gt;

&lt;p&gt;A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment). In other words, a closure gives you access to an outer function’s scope from an inner function. In JavaScript, closures are created every time a function is created, at function creation time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function sum(x){
  // outer functions scope
  return function(y){
  // inner functions scope
    return x + y
  }
 }
 const addSum = sum(3);
 console.log(addSum(6)) // print 9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In this example, we have defined a function sum(x), that takes a single argument y and returns the sum of x and y.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;sum&lt;/code&gt; is a &lt;strong&gt;function factory&lt;/strong&gt;. It creates functions that can add a specific value to their argument.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the example above, the function factory creates two new functions, one that adds three to its argument.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;addSum&lt;/code&gt; is closure. They share the same function body definition but store different lexical environments. In &lt;code&gt;addSum&lt;/code&gt; 's lexical environment, &lt;code&gt;x&lt;/code&gt; is 3.&lt;/p&gt;

&lt;p&gt;And then we call &lt;code&gt;addSum(6)&lt;/code&gt; the function return sum is 9, because &lt;code&gt;addSum&lt;/code&gt; already have x is 3 (share function body definition) and lexical environment received the argument y is 6 and it's a return sum of 3 and 6.&lt;/p&gt;

&lt;p&gt;Reference: &lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>What is a javascript engine?</title>
      <dc:creator>Edward Luu</dc:creator>
      <pubDate>Tue, 04 Aug 2020 16:25:12 +0000</pubDate>
      <link>https://dev.to/edwardluu/what-is-a-javascript-engine-12k0</link>
      <guid>https://dev.to/edwardluu/what-is-a-javascript-engine-12k0</guid>
      <description>&lt;h1&gt;
  
  
  Javascript Engine
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;A JavaScript engine is a computer program that executes JavaScript (JS) code. A JavaScript engine can be implemented as a standard interpreter, or just-in-time compiler that compiles JavaScript to bytecode in some form.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In a browser, the JavaScript engine runs in concert with the rendering engine via the Document Object Model.&lt;/p&gt;

&lt;h1&gt;
  
  
  List of popular projects that are implementing a JavaScript engine:
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;V8: open source, developed by Google, written in C++. Google Chrome and the many other Chromium-based browsers use it.&lt;/li&gt;
&lt;li&gt;SpiderMonkey: developed by Mozilla for use in Firefox and its forks.&lt;/li&gt;
&lt;li&gt;JavaScriptCore is Apple's engine for its Safari browser.&lt;/li&gt;
&lt;li&gt;Chakra (JScript9): Internet Explorer.&lt;/li&gt;
&lt;li&gt;Chakra (JavaScript): Microsoft Edge.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&amp;lt;&amp;lt; &lt;strong&gt;Next blog i will explain about to v8 engine.&lt;/strong&gt; &amp;gt;&amp;gt;&lt;/p&gt;

&lt;p&gt;Referances:&lt;br&gt;
&lt;a href="https://en.wikipedia.org/wiki/JavaScript_engine"&gt;https://en.wikipedia.org/wiki/JavaScript_engine&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Understanding Deep Copy and Shallow Copy in Javascript</title>
      <dc:creator>Edward Luu</dc:creator>
      <pubDate>Fri, 24 Jul 2020 09:19:57 +0000</pubDate>
      <link>https://dev.to/edwardluu/understanding-deep-and-shallow-copy-in-javascript-4im0</link>
      <guid>https://dev.to/edwardluu/understanding-deep-and-shallow-copy-in-javascript-4im0</guid>
      <description>&lt;h2&gt;
  
  
  Shallow copy
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Shallow copies duplicate as little as possible. A shallow copy of a collection is a copy of the collection structure, not the elements. With a shallow copy, two collections now share the individual elements.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Deep copy
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Deep copies duplicate everything. A deep copy of a collection is two collections with all of the elements in the original collection duplicated.&lt;/p&gt;
&lt;/blockquote&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fllosmmb3rzbq5ravmfcp.jpg" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fllosmmb3rzbq5ravmfcp.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Primitive data types
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;When you create these values, they are tightly coupled with the variable they are assigned to. They only exist once. That means you do not really have to worry about copying primitive data types in JavaScript. When you make a copy, it will be a real copy. &lt;br&gt;
Let’s see an example:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;6&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 5&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 6&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Reference data types
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Technically, arrays are also objects, so they behave in the same way. I will go through both of them in detail later.&lt;/p&gt;

&lt;p&gt;Here it gets more interesting. These values are actually stored just once when instantiated, and assigning a variable just creates a pointer (reference) to that value.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  With Object
&lt;/h3&gt;

&lt;p&gt;Create an object &lt;strong&gt;a&lt;/strong&gt; with property &lt;strong&gt;test&lt;/strong&gt; with value &lt;strong&gt;test1&lt;/strong&gt; and then copy &lt;code&gt;b = a&lt;/code&gt; and then change value &lt;strong&gt;test&lt;/strong&gt; in object &lt;strong&gt;b&lt;/strong&gt;.Let see example:&lt;/p&gt;

&lt;h4&gt;
  
  
  Shallow copy
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&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;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;test2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//Shallow copy&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// test 2&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// test 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Deep copy
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;test&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;test1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;//you can use spread or Object.assign() method for clone an object&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{...&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt; &lt;span class="c1"&gt;// or const b = Object.assign({},a);&lt;/span&gt;

&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;test2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Deep copy&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// test 1&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// test 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Making deep copies without thinking
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;test&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;test1&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;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&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="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;test2&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// test 1&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// test 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  With Arrays
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Copying arrays is just as common as copying objects.You can use some ways for deep copy are &lt;strong&gt;Spread Operator&lt;/strong&gt;,&lt;strong&gt;Array Functions&lt;/strong&gt;, &lt;strong&gt;Nested Array&lt;/strong&gt;.&lt;br&gt;
Let see an example below:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&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;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c1"&gt;// Spread Operator&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Array Functions&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Array Functions&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&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="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// Nested Array&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;In the end, you know should use the copy with reference data types for some case  you want to copy an object or array split with original and some ways how to make a deep copy.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thanks for reading.Please share your experiences,questions and feedback below!&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Reference
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.freecodecamp.org/news/copying-stuff-in-javascript-how-to-differentiate-between-deep-and-shallow-copies-b6d8c1ef09cd/" rel="noopener noreferrer"&gt;https://www.freecodecamp.org/news/copying-stuff-in-javascript-how-to-differentiate-between-deep-and-shallow-copies-b6d8c1ef09cd/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://stackoverflow.com/questions/184710/what-is-the-difference-between-a-deep-copy-and-a-shallow-copy" rel="noopener noreferrer"&gt;https://stackoverflow.com/questions/184710/what-is-the-difference-between-a-deep-copy-and-a-shallow-copy&lt;/a&gt;&lt;/p&gt;

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