Get the App
SLTechnology News&Howtos  ›  Development  › 

Instance Analysis of JavaScript object

Shulou Source: shulou.com Published: 2022-06-01 05:11:27 10月01日 Update

This article introduces the relevant knowledge of "JavaScript object instance Analysis". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

JavaScript objects are mutable

Objects are mutable: they are addressed by reference, not by value.

If person is an object, the following statement does not create a copy of person:

Var x = person; / / this does not create a copy of person.

Object x is not a copy of person. It is person. X and person are the same object.

Any change to x will change person because x and person are the same object.

Example

Var person = {firstName: "Bill", lastName: "Gates", age:62, eyeColor: "blue"}

Var x = person

X.age = 10; / / this will change both both x.age and person.age

Note: JavaScript variables are not mutable. Only JavaScript objects do this.

This is the end of "JavaScript object instance Analysis". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Objects examples copies case analysis analysis content more knowledge practicality identity success in learning and then this will not create variables only at the same time dilemmas reality that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Linux Xiaomi Shulou Technology Docker