Arrow Function JavaScript

How to write arrow function ?

Published 2021-07-16

JavaScript Arrow Function

const numbers = [0, 1, 2, 14, 22, 15]

const calc = (num) => {
  return num % 2 === 0 ? true : false
}

const isEven = (array) => {
 return array.forEach((e) => calc(e) ? console.log(`${e} is even`) : `` )
}

isEven(numbers)

If your Arrow function return a single line, you can write it shorter :

const numbers = [0, 1, 2, 14, 22, 15]

const calc = num => num % 2 === 0 ? true : false

const isEven = array => array.forEach((e) => calc(e) ? console.log(`${e} is even`) : `` )

isEven(numbers)

Related Tutorials :