Arrow Functions

 Arrow Functions


Arrow functions provide a concise syntax for writing function expressions in JavaScript.



const multiply = (a, b) => a * b;

console.log(multiply(5, 3)); // Output: 15


const greet = name => {

  console.log(`Hello, ${name}!`);

};

greet('John'); // Output: Hello, John!

The arrow function syntax (parameters) => { ... } allows for a more compact function declaration. If the function body consists of a single expression, you can omit the curly braces and the return statement.

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...