Arrow function inside "map" function CODE
Regular anonymous function:
let numbers = [10, 100, 1000]

let doubled = numbers.map(function(x){
  return x * 2
})

document.write(doubled)
Alternative arrow function:
let doubled = numbers.map((x) => { return x * 2 })
If it's only a single line we don't need curly brackets and the keyword
return
let doubled = numbers.map((x) => x * 2);
If the arrow function has only one parameter, it does not need parentheses:
let doubled = numbers.map(x => x * 2);
Note: We only need
parentheses
if we had zero or more than one parameters
by Valeri Tandilashvili
4 years ago
JavaScript
Functions
Arrow functions
2
Pro tip: use ```triple backticks around text``` to write in code fences