Q
What is the output of car.start() if var car = {start: function() {console.log('Car started');}};?

Answer & Solution

Answer: Option C
Solution:
The start method logs Car started to the console.
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)

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 create a method inside an object using an object literal?

A). methodName: function() {}

B). methodName = function() {}

C). methodName: () {}

D). methodName: method() {}

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

A). Honda

B). Civic

C). Undefined

D). Error

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

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.

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

A). methodName() {}

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

C). function methodName() {}

D). methodName: function() {}

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

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

A). Ford

B). Mustang

C). Undefined

D). Error

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