DEV Community

Dinesh G
Dinesh G

Posted on

My Java Full Stack Journey Learning in JavaScript

Arrow function

Arrow functions are a shorter way to write functions in JavaScript.

Syntax

Normal Function

function add(a, b) {
  return a + b;
}
Enter fullscreen mode Exit fullscreen mode

Arrow function

const add = (a, b) => {
  return a + b;
};
Enter fullscreen mode Exit fullscreen mode

Arrow Function in JavaScript

An Arrow Function is a shorter and cleaner way to write functions in JavaScript

.Writing compact functions

.Avoiding the function keyword

.Lexical binding of this (important difference from normal functions)

Syntax of Arrow function :

Traditional function:

function add(a, b) {
  return a + b;
}
Enter fullscreen mode Exit fullscreen mode

Arrow function

const add = (a, b) => {
  return a + b;
};
Enter fullscreen mode Exit fullscreen mode

one return function

const add = (a, b) => a + b;
Enter fullscreen mode Exit fullscreen mode

sub.map

()=>{ => (()=log("hi"))

const sub=[ ]
sub.map(()=> console.log("hii"));
sub.map(()=>prompt())

Enter fullscreen mode Exit fullscreen mode

[arrow function & call back function]

Happy coding...

Top comments (0)