arrow-function-expressions

Arrow functions in JavaScript are a concise way to define functions using the => syntax. They provide a more streamlined syntax for writing function expressions, especially when functions are short and simple. Arrow functions automatically capture the surrounding context's this value, making them particularly useful in callback functions and for avoiding issues with this scoping.

((arguments) =>code-to-execute)

simple arrow function


const greeting = (username) => console.log(`Hello ${username}`);
greeting("John");
      

simple arrow function with two arguments


const greeting2 = (username, age) =>
  console.log(`Hello ${username}, you are ${age} years old.`);
  
greeting2("John", 21);
      

sort an array using arrow functions


let grades = [20, 50, 70, 90, 40, 60, 30, 100, 14];

grades.sort((x, y) => y - x);
grades.forEach((element) => console.log(element));