JavaScript Interview Question #176
What is functional programming in JavaScript?
Advanced JavaScript, Practical Problems & Senior Interview Scenarios Senior Advanced
Quick Interview Answer
Functional programming is a style of programming that emphasizes functions, expressions, immutability, composition, and minimizing shared mutable state. JavaScript supports this style because functions are first-class values and can be passed, returned, and composed.
Detailed Explanation
Functional programming is a style of programming that emphasizes functions, expressions, immutability, composition, and minimizing shared mutable state. JavaScript supports this style because functions are first-class values and can be passed, returned, and composed.
In practical JavaScript, functional techniques often appear in array transformations, pure utility functions, reducers, and data-processing pipelines. A production application does not need to be purely functional to benefit from these ideas.
Code Example
const products = [
{ name: "A", price: 100 },
{ name: "B", price: 200 }
];
const discounted = products
.map(p => ({ ...p, price: p.price * 0.9 }))
.filter(p => p.price >= 100);
console.log(discounted);