Javascript - Functions - Arrow Functions


Arrow functions is a more compact and limited version of a function expression.

var func = (arg1, arg2, ..., argN) => expression
var sum = (a, b) => a + b;
console.log(sum(5, 2);)

If only one argument exists, parentheses can be omitted:

var square = n => n ** 2

When there are no arguments, parentheses are still required.

Multi-line arrow functions require {}

var sum_square = (a, b) => {
    let sum = a + b;
    return sum ** 2;
}