Question:

What does the following code print to the console?

function sum() {
  result = 0;
  arguments.forEach(function (num) {
    result += num;
  });
  return result;
}
sum(1, 2, 3);

Answer:

This code raises an error because arguments is an array-like object, but it's not actually an array, so we can't use the forEach() method. According to Douglas Crockford, having arguments as an array-like object and not an actual array is a design flaw in the language.


Keywords:

© 2017 QuizBucket.org