What are lambda expressions or arrow functions Flashcards

(3 cards)

1
Q

arrow functions

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Key Features

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Syntax Examples

A

const arrowFunc1 = (a, b) => a + b; // Multiple parameters, returns a + b
const arrowFunc2 = a => a * 10; // Single parameter (parentheses optional), returns a * 10
const arrowFunc3 = () => {}; // No parameters, returns undefined
const arrowFunc4 = (a, b) => {
// Multiple statements require curly braces and explicit return
const sum = a + b;
return sum * 2;
};

How well did you know this?
1
Not at all
2
3
4
5
Perfectly