MCQ Single Best Answer Not Set

QIn JavaScript, how should a new property be added to an object?

ID: #4854 Basic JavaScript MCQ 188 views
Question Info
#4854Q ID
Not SetDifficulty
Basic JavaScript MCQTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A obj.newProperty = 'value';
  • B obj.addProperty('newProperty', 'value');
  • C obj['newProperty'] = 'value';
  • D obj.set('newProperty', 'value');
Correct Answer: Option A

Explanation

obj.newProperty = 'value'; is the correct way to add a new property to an object in JavaScript.
You can use the dot notation (obj.property) or the square bracket notation (obj['property']) to add a new property to an object.

Share This Question

Challenge a friend or share with your study group.