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.

JavaScript Coding Question – 1

  • Here, in the above code the line const result = […new Set(arr)] removes duplicate values from the array arr using a Set, which only allows unique values.
  • new Set(arr): Creates a new Set from the array. The Set will only keep unique values.
  • [...new Set(arr)]: The spread operator ... is used to convert the Set back into an array.

Finding number of Elements of an Array which falls between two values.

To find how many elements of an array fall between two values ‘a’ and ‘b’, we can use the ‘filter’ method. This method allows us to iterate over the array and apply a condition to each element, returning a new array with the elements that meet the condition. We can get the count of elements by using the length.