
Arrow Functions in JavaScript
Modern JavaScript introduced arrow functions to make writing functions shorter and cleaner. They reduce unnecessary syntax and help developers write more readable code. Arrow functions are commonly used in modern JavaScript, especially when working with arrays, callbacks, and functional programming patterns. Why Arrow Functions? Sometimes normal functions require extra boilerplate code. Example using a normal function: function add ( a , b ) { return a + b ; } The same function written with an arrow function: const add = ( a , b ) => { return a + b ; }; The arrow syntax removes the need for the function keyword and makes the code more compact. Basic Arrow Function Syntax The general syntax of an arrow function looks like this: const functionName = ( parameters ) => { // code }; Example: const greet = () => { console . log ( " Hello! " ); }; greet (); Output: Hello! Arrow Functions with One Parameter If an arrow function has only one parameter , the parentheses are optional. Example: No
Continue reading on Dev.to Webdev
Opens in a new tab



