Developed By
Gautam Kumar - Full stack developer
DEEP DIVE INTO
Object literals is nothing, it's an object with key value pairs, which we already learned in previous chapter in object intro.
Example:
javascriptconst calculation = {
type: "Addition",
x : 10,
y: 20,
sum: () => return this.x + this.y;
}
The value can be a number, a string, an array, a function, or even another object. If the value is a function then it is known as a method. Here greet, x and y is called key or property and sum is called method.
Let's access the value.
javascriptconst typeValue = calculation.type; // "Addition"
const xValue = calculation.x; // 10
const xValue = calculation.y; // 20
const result = calculation.sum(); // 30