Q
How can you iterate over all properties of an object?

Answer & Solution

Answer: Option B
Solution:
The for...in loop iterates over all enumerable properties of an object.
Related Questions on Average

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

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

A). create

B). construct

C). new

D). 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

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 constructor function for a Car object?

A). function Car(make, model, year) { this.make = make; this.model = model; this.year = year; }

B). Car(make, model, year) { this.make = make; this.model = model; this.year = year; }

C). function create Car(make, model, year) { this.make = make; this.model = model; this.year = year; }

D). function construct Car(make, model, year) { this.make = make; this.model = model; this.year = year; }

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

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

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

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

C). this.methodName = () {}

D). this.methodName: () {}

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

A). Car

B). started

C). Car started

D). Error