React Native Geeks
18/09/2023
Excuses keep you in your comfort zone....
TOPIC:
IMPORTANCE OF OBJECTS IN JAVASCRIPT AND CONCEPT OF MUTABILITY OF OBJECTS
Why understanding objects in JavaScript is so much important?
Objects are king in JavaScript.
Objects are variables too. But objects can contain many values.
for instance:
const person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
this object contains more values than a variable.
here firstName, lastName, age and eysColor are called properties and the value they hold are called value. the value of age is 50 here.
Can you guess what's the code below is about?
const person = {};
person.firstName = "John";
person.lastName = "Doe";
person.age = 50;
person.eyeColor = "blue";
here we created an empty object then added four properties in it.
we can achieve the same result with:
const person = new Object();
person.firstName= "John";
person.secondName = "Doe";
perosn.age = 50;
person.eyeColor = "blue";
OBJECTS IN JAVASCRIPT ARE MUTABLE. FOR INSTACNE WE MAKE A COPY OF AN OBJECT AND DO CHANGES TO IT. THIS WILL ALSO CHANGE THE ORIGINAL OBJECT, TOO.
For example:
const person = {
firstName:"John",
lastName:"Doe",
age:50, eyeColor:"blue"};
const x = person;
here x is the copy of the person
now if we make changes in x by
x.age=100;
these changes will also change the person(that was our original object).
Hello my enthusiast programmer:::
Do you know the difference between the outputs of the following?
console.log(test);
var test = "reactNative";
console.log(test);
let test = "JavaScript";
leave comment
Click here to claim your Sponsored Listing.
Category
Contact the business
Telephone
Website
Address
Dhangri Road, Mansehra
Mansehra
21300