Advertisement
Arrow functions (also known as "lambda expressions") provide a concise syntax for writing function expressions in JavaScript. Introduced in ES6, arrow functions are often shorter and more readable, especially for simple operations or callbacks.
#### Key Features:
- Arrow functions do not have their own this, arguments, super, or new.target bindings. They inherit these from their surrounding (lexical) context.
- They are best suited for non-method functions, such as callbacks or simple computations.
- Arrow functions cannot be used as constructors and do not have a prototype property.
- They also cannot be used with new, yield, or as generator functions.
#### Syntax Examples:
1const arrowFunc1 = (a, b) => a + b; // Multiple parameters, returns a + b
2
3const arrowFunc2 = a => a * 10; // Single parameter (parentheses optional), returns a * 10
4
5const arrowFunc3 = () => {}; // No parameters, returns undefined
6
7const arrowFunc4 = (a, b) => {
8 // Multiple statements require curly braces and explicit return
9
10const sum = a + b;
11
12return sum * 2;
13};Advertisement
JavaScript Coding Exercise 11
Test your knowledge with this interactive coding challenge.
Start CodingAdvertisement