What does get fullName() { return this.first + " " + this.last; } inside an object literal allow?
A getter makes a computed property. Assigning to it does nothing (or throws in strict mode) unless a setter is also defined.
Objects · Exercise 1 of 4
Fifteen multiple-choice questions on JavaScript objects: dot and bracket notation, computed keys, keys as strings, delete, in vs hasOwn, methods and this, spread and Object.assign, freeze and seal, getters, descriptors, prototypes and JSON. Pick an option to check your answer instantly.
What does get fullName() { return this.first + " " + this.last; } inside an object literal allow?
A getter makes a computed property. Assigning to it does nothing (or throws in strict mode) unless a setter is also defined.
Why would you create a dictionary with Object.create(null) instead of {}?
A {} object inherits from Object.prototype, so "constructor" in dict is true even when you never added it. A null-prototype object starts truly empty.
What does Object.entries({ a: 1, b: 2 }) return?
An array of [key, value] pairs for own enumerable string keys – ideal with for…of and destructuring, and reversible with Object.fromEntries.
After Object.defineProperty(o, "id", { value: 7 }) on a new property, which is true?
defineProperty defaults writable, enumerable and configurable to false for new properties, so id is hidden from Object.keys and JSON and cannot be changed or deleted.
What does Object.assign(config, overrides) do?
The first argument is mutated. To keep config unchanged, pass a fresh target: Object.assign({}, config, overrides) – or use spread.
Timed online tests with instant scores and explanations.