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

Comments: 2

profile
@niteshguptav63
17-Nov-2024, 01:39 PM

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

profile
@niteshguptav63
16-Nov-2024, 10:56 AM

When will I get my course?

profile
@admin79
17-Nov-2024, 01:29 PM

Now, Your query was resolved.

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?