Objects

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 203:- Objects

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

22. Constructors And Prototypes

2 Comments

@niteshguptav63
niteshguptav63 Nov 17, 2024 at 1:39 PM

I am not able to access videos from second class and further. I have already completed first class

@niteshguptav63
niteshguptav63 Nov 16, 2024 at 10:56 AM

When will I get my course?

@admin79
admin79 Nov 17, 2024 at 1:29 PM

Now, Your query was resolved.

Frequently Asked Questions About Sciaku Courses & Services

Quick answers to common questions about our courses, quizzes, and learning platform

Didn't find what you're looking for?

help_center Contact Support