An Interest In:
Web News this Week
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
November 29, 2022 12:50 pm GMT
Original Link: https://dev.to/jindalkeshav82/objects-in-javascript-31bh
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:
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:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To