JavaScript Arrow Function

BASIC SYNTAX

function (a){ return a + 100; }

// Arrow Function Break Down

// 1. Remove the word "function" and place arrow between the argument and opening body bracket

(a) => { return a + 100; } // 2. Remove the body brackets and word "return" -- the return is implied.

(a) => a + 100; // 3. Remove the argument parentheses

a => a + 100;

1 PARAMETER

var hello; hello = () => { return "Hello World1!"; }

function hello2() { return "Hello World2!"; }

function add(a) { a="supu"; return a+"arthi"; }

// breakdown the arrow fun

add2 = (a) => { a=20; return a+"wooo"; }

// remove{} and "return" add3=(a=11) => a+"hulk";

//remove the unwanted () paranthesis

add4= (a=20) =>a+100;



ANSWERS


2 PARAMETERS

function parrot(alpha ,beta){ alpha="bat"; beta="man"; return alpha+beta+"wow"; }

// Arrow Function (no arguments)

par21=(alpha=20,beta=40) => alpha + beta + 100;



ANSWERS