Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
November 29, 2022 12:50 pm GMT

Objects in JavaScript.

1. What are Objects
Objects are one of the datatype in JavaScript which is very useful as it can store multiple type of values like: string, Boolean, int, etc.
For example:

Image description

Properties  book.name= Harry Potter         book.color= Purplebook.size= A4

2. Accessing the data
for example:

const person = {  firstName: "John",  lastName: "Doe",  age: 50,  eyeColor: "blue"};console.log(person.age);console.log(person.eyecolor);

Output:
50
blue
3. Object Methods
Object Methods can be accessed by using functions which are stored as properties in JavaScript.
Example:

const my_object = {  firstName: "Ronn",  lastName : "Doe",  uid       : 9980,  fullName : function() {    return this.firstName + " " + this.lastName;  }};console.log(my_object)

Output:
const my_object = {
firstName: "Ronn",
lastName : "Doe",
uid : 9980,

}
};
firstName: "Ronn"
lastName: "Doe"
uid: 9980
4. Accessing Object Methods
SYNTAX:
object_name.property;
object_name["property"]


Original Link: https://dev.to/jindalkeshav82/objects-in-javascript-31bh

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To