When creating JavaScript objects with properties, why do I need this code?

I read about JavaScript prototypes here . The Object.create header contains code to illustrate the creation of objects with prototypes and some properties:

var person = {
    kind: 'person'
}

// creates a new object which prototype is person
var zack = Object.create(person);

console.log(zack.kind); // => β€˜person’

Then I came across this:

var zack = Object.create(person, {age: {value:  13} });
console.log(zack.age); // => β€˜13’

Instead of passing, {age: {value: 13} }I went through {age: 13}because it seemed simpler. Unfortunately, it was thrown out TypeError. To create properties of this object like this, why do we need to pass {age: {value: 13} }, not just {age: 13}?

+4
source share

All Articles