carlCodes.tech

Brain growing from plant

Blog:
JavaScript Arrow Functions

JavaScript Arrow Functions

Arrow functions, provide a more concise way to write function expressions in JavaScript.

They're especially handy for callbacks or functions that don't require their own this context.

Here's a basic example of a regular function and an arrow function:



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

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

Key Points:

  • Concise way of writing a function.
  • If the function body is a single expression, neither the 'return' keyword or curly brackets are needed.
  • They do not have their own 'this' context.