JavaScript Coding Question – 13

Output:

[
  [ 'firstName', 'abc' ],
  [ 'lastName', 'xyz' ],
  [ 'age', 50 ]
]
  • Above code will convert the properties of the Person object into an array of key-value pairs using Object.entries().
  • Object.entries(Person) : takes each property of the Person object and convert it into an array, where each element is a [key, value] pair.

JavaScript Coding Question – 11

  • Object.assign(obj2, obj1) : merges obj1 properties into obj2.( adding the properties from obj1 into obj2 directly.)
  • Object.keys(obj2): Gets the keys of the modified obj2.
  • Since obj1’s keys (a and b) are added to obj2, result includes all keys from both objects.

JavaScript Coding Question – 2

Output:

true
  • expr1 = (null <= 0): In JavaScript, null is converted to ‘0’ when compared with number which makes null <= 0 evaluate to true.
  • expr2 = ('' == false): The == operator performs type coercion. An empty string ('') is coerced to a number, which results in 0. Thus, '' == false evaluates to true because false is also coerced to 0.
  • result = (expr1 === expr2): Since both expr1 and expr2 are true, the comparison true === true evaluates to true.