What are lambda expressions or arrow functions
Arrow functions (also called lambda expressions in some languages) are a shorter way to write functions in JavaScript. They were introduced in ES6 (ECMAScript 2015).
Syntax:
const add = (a, b) => a + b;
Instead of:
function add(a, b) { return a + b; }
Key Points for Interviews
- Shorter and cleaner syntax.
-
Do not have their own
this; they inheritthisfrom the surrounding scope (lexicalthis). -
Best for callbacks (
map,filter,reduce,setTimeout, etc.). -
Cannot be used as constructors with
new.
One-line Interview Answer
"Arrow functions are a concise way to write functions in JavaScript. They use the
=>syntax, inheritthisfrom their surrounding scope (lexicalthis), and are commonly used for callbacks and cleaner code."
Comments
Post a Comment