Question:

What does the following code print to the console?

function sum (x, y) {
  return this.name + ", the sum is " + (x + y);
}

person = {
  name: "Phil"
}

console.log(sum.call(person, 2, 2));

Answer:

Phil, the sum is 4

The call() method is similar to apply(), but it takes the parameters as arguments instead of an array.


Keywords:

© 2017 QuizBucket.org