loading...

re: Make Your Code Cleaner, Shorter and Easier to Read! ES6 Tips and Tricks. VIEW POST

FULL DISCUSSION
 

Great article but I think there is a typo in this code example

let a = [1, 2, 3];
let b = [ ...a ];
let c = a;
b.push(4);
console.log(a);  // [1, 2, 3]
console.log(b);  // [1, 2, 3, 4] referencing different arrays
c.push(5);
console.log(a);  // [1, 2, 3, 5] 
console.log(b);  // [1, 2, 3, 5] referencing the same array

Should the last line console.log(c)?

 

Thanks Alex, I'll change it now.

 

Yeah I saw that too. There should be console.log(c) because b is still [1,2,3,4];

P.S. Awesome article from Author.

code of conduct - report abuse