Loading Please Wait...
In JavaScript, objects are king. If you understand objects, you understand JavaScript.
In JavaScript, almost "everything" is an object.
Objects are variables too. But objects can contain many values.
The values are written as name:value pairs (name and value separated by a colon). It is a common practice to declare objects with the const keyword.
const user = { name:"John Doe", email:"john@gmail.com" };
With JavaScript, you can define and create your own objects. There are different ways to create new objects.
This is the easiest way to create a JavaScript Object.
Using an object literal, you both define and create an object in one statement.
An object literal is a list of name:value pairs (like age:50) inside curly braces {}.
const user = { name:"John Doe", email:"john@gmail.com" };
// OR
const user = {
name:"John Doe",
email:"john@gmail.com"
};
You can create an object using new Object().
const user = new Object();
user.name = "John Doe";
user.email = "john@gmail.com";
There is no need to use new Object(). For readability, simplicity and execution speed, use the object literal method.
const user = {};
user.name = "John Doe";
user.email = "john@gmail.com";
Objects are mutable. They are addressed by reference, not by value.
const x = user; // Will not create a copy of user.
The object x is not a copy of user. It is user. Both x and user are the same object.
Any changes to x will also change user, because x and user are the same object.
const user = { name:"John Doe", email:"john@gmail.com" };
const x = user;
x.email = "john@gmail.com"; // Will change both x.email and user.email
How you feel about this blog:
Share this blog on:
If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com
Contact UsWe are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..
Copyright ©
, Lynxsia IT Solutions, All rights reserved