What will be the output of the following JavaScript code? [code] const obj1 = { a: 10, b: 15, c: 18 }; const obj2 =

Danh Trịnh

New member
What will be the output of the following JavaScript code?
Code:
const obj1 = 
{  
  	a: 10,  
  	b: 15,  
  	c: 18  
};  
const obj2 = Object.assign({c: 7, d: 1}, obj1);  
console.log(obj2.c, obj2.d);
A. 7,1
B. 18,1
C. Undefined
D. Error
 
Answer: a
Explanation: The Object.assign() method is used to copy the properties and values of one object to another. Objects are assigned and copied by reference.
 

Tìm kiếm

Back
Top