Created
November 11, 2020 15:52
-
-
Save fredriccliver/dc6a741e0b8d7f5455877c38a6e26fbc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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