1. Before Arrow
While both of these approaches have their uses, they can be verbose and hard to read when dealing with small, one-line functions. Arrow Functions provide a more concise syntax for these cases and offer some additional benefits, such as lexical scoping and implicit return.
2. With Arrow Function
3. Arrow Functions Return Value by Default
4. Arrow Function With Parameters
The arrow function greet takes a single parameter name, but if no argument is passed in, it defaults to the string "World". The function then logs a message to the console using string interpolation to include the value of the name parameter. Arrow functions can also use the rest parameter syntax to accept an arbitrary number of arguments as an array.
5. Arrow Function Without Parentheses
If you have no parameters, you still need to include empty parentheses to indicate that the function takes no arguments. While omitting the parentheses can make your code more concise and readable, it's important to note that it can also make your code less clear if you have multiple parameters or complex expressions. In those cases, it's usually better to include the parentheses for clarity.