DEV Community

Dharshini E
Dharshini E

Posted on

Javascript - arrow function

Understanding Arrow Functions, Callback Functions, and the Map Function in JavaScript
1. Arrow Functions:

  • Arrow functions are a shorter way to write functions in JavaScript.
  • They were introduced in ES6 and make the code cleaner and easier to read.
  • It provides a shorter and more readable way to define functions, especially for anonymous functions or callbacks.
// Normal function
function add(a, b) {
  return a + b;
}

// Arrow function
const addArrow = (a, b) => a + b;

console.log(add(2, 3));       // Output: 5
console.log(addArrow(2, 3));  // Output: 5


Enter fullscreen mode Exit fullscreen mode

Top comments (0)