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

Answer & Solution

Answer: Option A
Solution:
The in operator checks if a property exists in an object.
Related Questions on Average

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

A). methodName() {}

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

C). function methodName() {}

D). methodName: function() {}

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

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

Which of the following is the correct way to delete a property from an object?

A). remove object.property;

B). delete object.property;

C). delete object[property];

D). object.property = null;

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

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

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

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

A). Ford

B). Mustang

C). Undefined

D). Error