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,639
  • 2
  • 25
  • 43
Thorben Croisé
  • 12,407
  • 8
  • 39
  • 50
  • 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