Q
How do you add a new property to an existing object in JavaScript?

Answer & Solution

Answer: Option A
Solution:
In JavaScript, you can add a new property to an object using dot notation.
Related Questions on Average

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 is the output of car.start() if var car = {start: function() {console.log('Car started');}};?

A). Car

B). started

C). Car started

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 will car['make'] return if var car = {make: 'Ford', model: 'Mustang'};?

A). Ford

B). Mustang

C). Undefined

D). Error

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

How do you create a method inside an object using an object literal?

A). methodName: function() {}

B). methodName = function() {}

C). methodName: () {}

D). methodName: method() {}

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

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

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

A). methodName() {}

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

C). function methodName() {}

D). methodName: function() {}