0 day streak
javascript / beginner
Snippet

Concise Logic with Arrow Functions

Arrow functions provide a shorter syntax for writing function expressions. They are especially useful for simple logic and passing functions as arguments.

snippet.js
javascript
1
2
3
const getGreeting = (name) => `Hello, ${name}`;
console.log(getGreeting('Next.js User'));
nextjs
Breakdown
1
const getGreeting = (name) => ...
Defines a function using the fat arrow (=>) syntax.
2
getGreeting('Next.js User')
Calls the function with a specific string argument.