If you have any query feel free to chat us!
Happy Coding! Happy Learning!
An object is a data structure that stores data and behaviors as key-value pairs. Objects in JavaScript are similar to objects in real life, in the sense that they are made up of properties (the object's attributes) and methods (the object's behaviors).
In JavaScript, an object is created using curly braces {}
with key-value pairs separated by commas ,
. For example:
javascriptCopy code
let person = {
name: "John",
age: 25,
sayHello: function() {
console.log("Hello!");
}
};
This creates an object person
with three properties: name
, age
, and sayHello
. The name
and age
properties are simple values (strings and numbers, respectively), while the sayHello
property is a function.
You can access the properties and methods of an object using dot notation objectName.propertyName
or bracket notation objectName["propertyName"]
. For example:
javascriptCopy code
console.log(person.name); // Output: John
console.log(person["age"]); // Output: 25
person.sayHello(); // Output: Hello!
You can also add or modify properties and methods of an object using the same dot or bracket notation. For example:
javascriptCopy code
person.job = "Developer";
person["isMarried"] = false;
console.log(person.job); // Output: Developer
console.log(person["isMarried"]); // Output: false
You can also delete properties of an object using the delete
keyword. For example:
javascriptCopy code
delete person.job;
console.log(person.job); // Output: undefined
Finally, you can loop through the properties and methods of an object using a for...in
loop. For example:
javascriptCopy code
for (let key in person) {
console.log(key + ": " + person[key]);
}
This will output:
vbnetCopy code
name: John
age: 25
sayHello: function() {
console.log("Hello!");
}
isMarried: false
Comments: 2
I am not able to access videos from second class and further. I have already completed first class
When will I get my course?
Now, Your query was resolved.