Q
What will the following code output? console.log(car.make); if var car = {make: 'Honda', model: 'Civic'};

Answer & Solution

Answer: Option A
Solution:
The make property of the car object is Honda, so it outputs Honda.
Related Questions on Average

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)

In JavaScript, what keyword is used to define a new object from a constructor function?

A). create

B). construct

C). new

D). object

How can you check if a property exists in an object?

A). 'property' in object

B). object.hasProperty('property')

C). object.contains('property')

D). object.includes('property')

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');

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

A). Ford

B). Mustang

C). Undefined

D). Error

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 do you define a method in a constructor function?

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

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

C). this.methodName = () {}

D). this.methodName: () {}

What is the purpose of the this keyword in an object method?

A). It refers to the global object.

B). It refers to the current object.

C). It refers to the parent object.

D). It refers to the previous object.

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.keys(obj) return?

A). An array of the values of the object's properties

B). An array of the names of the object's properties

C). The first key of the object

D). The number of properties in the object