Q
How do you add a method to an object created wit...

Answer & Solution

Answer: Option A
Solution:
Methods in a constructor function are added using 'this.methodName = function() {};'.
Related Questions on Average

What does the Object.values(obj) method return?

A). An array of object keys.

B). An array of object values.

C). An array of object properties.

D). An array of object methods.

What will console.log(obj.toString()) output?

A). The string representation of...

B). The object itself.

C). An error.

D). 1

How can you remove a property 'email' from an obj...

A). delete user.email;

B). user.remove('email');

C). user.email = null;

D). user.pop('email');

How do you check if an object has a property 'col...

A). 'color' in obj

B). obj.hasProperty('color');

C). obj.contains('color');

D). obj.propertyExists('color');

What is the output of console.log(obj.prop) if ob...

A). It prints undefined.

B). It throws an error.

C). It prints null.

D). It prints true.

What happens if you access a non-existent property...

A). It returns undefined.

B). It throws an error.

C). It returns null.

D). It returns true.

How do you create an instance of the 'Car' objec...

A). var myCar = new Car('Toyota', ...

B). var myCar = Car('Toyota', 'Corol...

C). var myCar = create Car('Toyota',...

D). var myCar = construct Car('Toyo...

How do you define a method 'sayHello' in an obj...

A). person.sayHello = function() {};

B). person.sayHello: function() {};

C). person.sayHello = () {};

D). person.sayHello = function {};

How do you access nested properties in an object?

A). obj.property.nestedProp (B21)

B). obj['property']['nestedProp'] (C21)

C). obj.property['nestedProp'] (D21)

D). obj['property'].nestedProp (E21)

What does Object.keys(obj) return?

A). An array of object keys.

B). An array of object values.

C). An array of object properties.

D). An array of object methods.