Q
How do you define a constructor function for creating Car objects?

Answer & Solution

Answer: Option A
Solution:
Constructor functions are defined using the function keyword followed by the function name and parameters.
Related Questions on Average

What is the output of console.log(person.greet()); if var person = {greet: function() {return 'Hello';}};?

A). Hello

B). Undefined

C). Error

D). Hello

What will the following code output? console.log(person['age']); if var person = {name: 'John'};

A). 30

B). John

C). undefined

D). null

How do you iterate over all properties of an object var person = {name: 'John', age: 30};?

A). for (var key in person)

B). for (var key of person)

C). forEach(key in person)

D). forEach(key of person)

What will console.log(car.make); output if var car = {make: 'Toyota', model: 'Corolla'};?

A). Toyota

B). Corolla

C). Undefined

D). Error

What does Object.keys(person) return if var person = {name: 'John', age: 30};?

A). ['name', 'age']

B). ['John', 30]

C). {'name', 'age'}

D). {'John', 30}

How do you access the value of the name property in the object var person = {name: 'John', age: 30};?

A). person['name']

B). person.name

C). person->name

D). person::name

How do you call a method from a parent class in a subclass in JavaScript ES6?

A). super.methodName()

B). this.methodName()

C). parent.methodName()

D). base.methodName()

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 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() {} }

How do you add a method to an object created with a constructor function?

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

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

C). this.methodName = () {}

D). this.methodName: () {}