Q
What does Object.keys(obj) return?

Answer & Solution

Answer: Option B
Solution:
Object.keys(obj) returns an array containing the names of all the object's own enumerable properties.
Related Questions on Average

How do you define a method inside a class in JavaScript ES6?

A). methodName() {}

B). this.methodName = function() {}

C). function methodName() {}

D). methodName: function() {}

Which method can be used to call a function defined within an object?

A). object.functionName();

B). object->functionName();

C). object::functionName();

D). object.callFunction('functionName');

What is encapsulation in the context of JavaScript objects?

A). Hiding the internal state and requiring all interaction to be performed through an object's methods

B). Extending one object from another

C). Creating a new object

D). Removing a property from an object

What does Object.assign(target, ...sources) do?

A). Copies properties from sources to target

B). Compares properties between target and sources

C). Deletes properties in sources

D). Merges properties of sources into target and removes duplicates

How can you iterate over all properties of an object?

A). for (var key of object)

B). for (var key in object)

C). for (var key with object)

D). for (var key over object)

What will car['make'] return if var car = {make: 'Ford', model: 'Mustang'};?

A). Ford

B). Mustang

C). Undefined

D). Error

How do you define a class in JavaScript ES6?

A). class ClassName { constructor() {} }

B). function ClassName() { constructor() {} }

C). class ClassName() { constructor {} }

D). function class ClassName { constructor() {} }

Which of the following correctly creates an instance of a Car object using a constructor function?

A). var myCar = Car('Toyota', 'Corolla', 2020);

B). var myCar = new Car('Toyota', 'Corolla', 2020);

C). var myCar = create Car('Toyota', 'Corolla', 2020);

D). var myCar = construct Car('Toyota', 'Corolla', 2020);

How do you add a new property to an existing object in JavaScript?

A). object.property = value;

B). object->property = value;

C). object:property = value;

D). object.addProperty('property', value);

Which of the following is a correct way to define an object using an object literal?

A). var car = {make: 'Toyota', model: 'Corolla'};

B). var car = make: 'Toyota', model: 'Corolla';

C). var car = new Object(make: 'Toyota', model: 'Corolla');

D). var car = Object.create(make: 'Toyota', model: 'Corolla');