Today I learned about arrow functions in JavaScript.
An arrow function is a shorter way to write a function.
Normal function
function add(a, b) {
return a + b;
}
Arrow function
const add = (a, b) => a + b;
Here:
const add → stores the function
(a, b) → parameters
=> → arrow function syntax
a + b → returned result
Example:
console.log(add(10, 20));
Output:
30
The shorter syntax makes simple functions easier to write and read.
Top comments (0)