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 inherit this from the surrounding scope (lexical this).
  • 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, inherit this from their surrounding scope (lexical this), and are commonly used for callbacks and cleaner code."

Comments

Popular posts from this blog

What is Class in js