Chapter: 5 – Notes – Arrow Function – JavaScript for React Beginners

Arrow functions are a shorter way to write functions in JavaScript, introduced in ES6 (2015).
They have a cleaner syntax and also handle the this keyword differently compared to regular functions.

Basic Syntax

Regular function:

function add(a, b) {
  return a + b;
}

Arrow function:

const add = (a, b) => {
  return a + b;
};

If the function body is a single expression, you can omit the curly braces {} and the return keyword:

const greet = () => console.log("Hello!");
greet(); // Output: Hello!

About the Author: smartcoder

You might like

Leave a Reply

Your email address will not be published. Required fields are marked *