0

Why does the second line throw an error?

[0,1,2].forEach(function(x) { console.log(x) }); // prints 0, 1, 2
[0,1,2].forEach(console.log); // throws "TypeError: Illegal invocation"
Sobin Augustine
  • 3,363
  • 2
  • 24
  • 42
Thorben Croisé
  • 11,429
  • 8
  • 36
  • 47
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Bound_functions_used_as_constructors – Kelu Thatsall Sep 12 '13 at 12:34
  • http://stackoverflow.com/questions/8904782/uncaught-typeerror-illegal-invocation-in-javascript – ganoro Sep 30 '13 at 07:24

0 Answers0