Frank Tian
Frank Tian

Reputation: 807

Reference Data Type compares with Primitive Data Type in JavaScript

I am a little bit confused about this topic for example

var person = "Kobe";
var another = person;

is variable another create an another copy or just reference to person? That being said, if I change person to something else, will another also be changed??

Compare to

var person = {name: "Kobe"};
var another = person;

Thanks for the help

Upvotes: 0

Views: 81

Answers (1)

lexasss
lexasss

Reputation: 302

Strings (also numbers and booleans) are copied on assignment in JS, object and function share references

Upvotes: 1

Related Questions