0 day streak
javascript / beginner
Snippet

Arrow Functions

Arrow functions provide a shorter syntax for writing function expressions. They are particularly useful for simple, one-line operations and behave differently with the 'this' keyword compared to regular functions.

snippet.js
javascript
1
2
3
const multiply = (a, b) => a * b;
console.log(multiply(5, 2));
nodejs
Breakdown
1
const multiply = (a, b) => a * b;
Declares a constant 'multiply' that takes two parameters and returns their product immediately.
2
console.log(multiply(5, 2));
Calls the arrow function and prints the result (10) to the console.