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

Answer & Solution

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

How do you inherit properties and methods from another class in JavaScript ES6?

A). class SubClass extends SuperClass {}

B). class SubClass inherits SuperClass {}

C). class SubClass implements SuperClass {}

D). class SubClass super SuperClass {}

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

A). 30

B). John

C). undefined

D). null

What is the correct way to create an object in JavaScript?

A). var obj = {};

B). var obj = [];

C). var obj = ();

D). var obj = <>;

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

A). Toyota

B). Corolla

C). Undefined

D). Error

What will console.log(newCar.make); output if class Car { constructor(make) { this.make = make; }} var newCar = new Car('Honda');?

A). Honda

B). Car

C). Undefined

D). Error

How can you check if the age property exists in the person object?

A). 'age' in person

B). person.has('age')

C). person.contains('age')

D). person.hasOwnProperty('age')

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

How do you add a new property gender with value male to the person object?

A). person.gender = 'male';

B). person.gender = male;

C). person.gender = ['male'];

D). person[gender] = 'male';

What is the purpose of the this keyword in a constructor function?

A). It refers to the new object being created.

B). It refers to the global object.

C). It refers to the current object.

D). It refers to the parent 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() {}