Skip to content

Instantly share code, notes, and snippets.

@fredriccliver
Created November 11, 2020 15:52
Show Gist options
  • Save fredriccliver/dc6a741e0b8d7f5455877c38a6e26fbc to your computer and use it in GitHub Desktop.
Save fredriccliver/dc6a741e0b8d7f5455877c38a6e26fbc to your computer and use it in GitHub Desktop.
// This work with assigning by value
var i = 3
// 3
j = i
// 3
j += 1
// 4
i
// 3
j
// 4
// This work with assigning by reference
var i = [1,2,3]
i // (3) [1,2,3]
j = i
// (3) [1,2,3]
j.push(4)
// 4
j // (4) [1,2,3,4]
i // (4) [1,2,3,4]
// This make assign only value, rather than assign reference
var i = [1,2,3]
var j = [...i]
j.push(4)
// 4
i
// (3) [1,2,3]
j
// (4) [1,2,3,4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment