0

What is the difference between the following two ways to iterate over arrays using forEach in Javascript?

array1.forEach(element => console.log(element));

array1.forEach(function(element) {console.log(element)});
BlueSkies
  • 109
  • 8
  • They are equivalent (for the most part) - your first example uses [`arrow functions`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) – Matt Oestreich Dec 14 '19 at 22:16
  • The first one is often used in ES6. https://engineering.carsguide.com.au/es5-vs-es6-syntax-6c8350fa6998 – node_modules Dec 14 '19 at 22:17
  • Look up difference between old standard function closure and new arrow function syntax. – Akxe Dec 14 '19 at 22:17

0 Answers0