Creating Objects
JS · Objectssyntax
const obj = { key: value };
const obj = Object.create(proto);example
const user = {
name: "Kai",
age: 30,
greet() {
return `Hi, I'm ${this.name}`;
}
};
console.log(user.greet());output
"Hi, I'm Kai"Note Method shorthand greet() {} is preferred over greet: function() {}. Arrow functions should not be used as methods because they do not bind their own this.