FUNDAMENTALS OF COMPUTER

COMPUTER PROGRAMMING FUNDAMENTALS

WHAT IS PROGRAMMING

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Let’s say you’re storing an object in a variable named ‘pumpkin’. Which line of code would add a new property ‘eyes’ to the object?
A
pumpkin.push({eyes:‘green’});
B
pumpkin[eyes] = ‘green’;
C
pumpkin.eyes = ‘green’;
D
var pumpkin.eyes = ‘green’
Explanation: 

Detailed explanation-1: -JavaScript will return ‘undefined’ if we try to access properties or call methods that do not exist in the given object.

Detailed explanation-2: -Using the assign () method In JavaScript, assign() is an in-built method. Using the assign() method, we can assign or add a new value to an existing object or we can create the new object without changing the existing object values.

Detailed explanation-3: -Which of the following code creates an object? Explanation: var book = new Object(); will create an object.

Detailed explanation-4: -Some of the ways to add a property to an object JavaScript include: using dot notation, using bracket [ ] notation, using the defineProperty() method, using the spread operator, and using the Object. assign() method.

There is 1 question to complete.