0
0
Javascriptprogramming~5 mins

Object.create usage in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does Object.create() do in JavaScript?

Object.create() creates a new object with the specified prototype object and properties. It lets you set the prototype of the new object directly.

Click to reveal answer
beginner
How do you create an object with Object.create() that inherits from another object?
<p>Pass the object you want to inherit from as the first argument to <code>Object.create()</code>. For example: <code>const child = Object.create(parent);</code></p>
Click to reveal answer
intermediate
What is the difference between Object.create(null) and {}?

Object.create(null) creates an object with no prototype, so it doesn't inherit any properties like toString. {} creates an object that inherits from Object.prototype.

Click to reveal answer
intermediate
Can you add properties when creating an object with Object.create()?

Yes, the second argument of Object.create() lets you define properties with descriptors. For example: Object.create(proto, { prop: { value: 42, writable: true, enumerable: true, configurable: true } }).

Click to reveal answer
intermediate
Why might you use Object.create() instead of a constructor function?

It gives you direct control over the prototype chain without needing to define a constructor. This can be simpler for creating objects that inherit from others without extra setup.

Click to reveal answer
What is the first argument to Object.create()?
AA constructor function
BAn array of property names
CThe prototype object for the new object
DA string representing the object type
What does Object.create(null) create?
AAn object with no prototype
BAn empty array
CAn object with default properties
DA function object
How can you add properties when using Object.create()?
ABy calling <code>addProperty()</code> method
BBy passing a second argument with property descriptors
CBy passing an array of values as the second argument
DYou cannot add properties during creation
Which of these is true about objects created with Object.create()?
AThey inherit from the object passed as the first argument
BThey always have <code>Object.prototype</code> as prototype
CThey cannot have methods
DThey are frozen by default
Why use Object.create() instead of a constructor function?
ABecause it automatically adds methods
BBecause it runs faster
CBecause it creates arrays
DTo directly set the prototype without defining a constructor
Explain how Object.create() works and how it is used to set an object's prototype.
Think about how inheritance works in JavaScript objects.
You got /4 concepts.
    Describe the difference between an object created with Object.create(null) and a normal object literal {}.
    Consider what properties and methods are available on each.
    You got /3 concepts.