Functional Programming Concepts Interview Questions Hindi mein

Functional Programming Concepts कोर्स के 25 सवाल, हर सवाल के सही जवाब और explanation के साथ। जवाब देखने से पहले ख़ुद सोचें।

Foundations of Functional Programming

1. Which statement best describes declarative code?

  1. It cannot be written in JavaScript
  2. It always runs faster than imperative code
  3. It states what result is wanted and delegates the step-by-step control flow
  4. It avoids using functions
जवाब देखें

जवाब: It states what result is wanted and delegates the step-by-step control flow

Declarative code focuses on the result; performance depends on the implementation.

पाठ: What Functional Programming Is

2. Which function is pure?

  1. `(a, b) => a + b`
  2. `(x) => { console.log(x); return x; }`
  3. `() => Math.random()`
  4. `(arr) => { arr.sort(); return arr; }`
जवाब देखें

जवाब: `(a, b) => a + b`

Logging, randomness and in-place sorting are all side effects or hidden inputs.

पाठ: Pure Functions and Referential Transparency

3. Why isolate side effects from business logic?

  1. Because effects always slow programs down
  2. Because side effects are forbidden in JavaScript
  3. To make programs unable to perform I/O
  4. The logic becomes testable with plain inputs and outputs, and effects are confined to a small layer
जवाब देखें

जवाब: The logic becomes testable with plain inputs and outputs, and effects are confined to a small layer

FP keeps effects, but moves them to the edges.

पाठ: Side Effects and Why Isolating Them Helps

Immutability

4. What does immutability make cheap?

  1. Updating very large arrays in place
  2. Detecting changes by comparing references
  3. Avoiding all memory allocation
  4. Mutating objects shared across modules
जवाब देखें

जवाब: Detecting changes by comparing references

If values never change, a different reference means different content.

पाठ: Immutable Data and Why It Matters

5. After `const b = { ...a }`, what is true of a nested object `a.inner`?

  1. `b.inner` is a deep copy
  2. `b.inner` is the same object as `a.inner`
  3. `b.inner` is undefined
  4. `a.inner` is frozen
जवाब देखें

जवाब: `b.inner` is the same object as `a.inner`

Spread copies only one level.

पाठ: Copying versus Structural Sharing

6. What does `const obj = {...}` guarantee in JavaScript?

  1. The object is copied on every read
  2. The object is deeply immutable
  3. The object is frozen at runtime
  4. The variable cannot be reassigned, but the object can still be mutated
जवाब देखें

जवाब: The variable cannot be reassigned, but the object can still be mutated

const is about the binding, not the value.

पाठ: Immutability in Practice

Functions as Values

7. Which is a higher-order function?

  1. A function that accepts a callback as an argument
  2. Any function with more than three parameters
  3. A function declared at the top of a file
  4. A function that returns a number
जवाब देखें

जवाब: A function that accepts a callback as an argument

Higher-order means it works with functions as values.

पाठ: First-Class and Higher-Order Functions

8. Why is `makeCounter()`'s returned function not pure?

  1. It has no parameters
  2. Closures are always impure
  3. It reads and updates captured mutable state, so repeated calls give different results
  4. It is defined inside another function
जवाब देखें

जवाब: It reads and updates captured mutable state, so repeated calls give different results

Closing over constants keeps purity; closing over mutable state does not.

पाठ: Closures

9. When is a plain loop often the better choice?

  1. Never; loops are forbidden in FP
  2. Whenever the array has more than ten elements
  3. When you need early exit or the reduce callback becomes hard to follow
  4. When you want to keep the source array unchanged
जवाब देखें

जवाब: When you need early exit or the reduce callback becomes hard to follow

Readability decides; FP is a tool, not a rule.

पाठ: map, filter and reduce

Composition

10. In what order does `pipe(a, b, c)(x)` apply the functions?

  1. `a` first, then `b`, then `c`
  2. `c` first, then `b`, then `a`
  3. All three in parallel
  4. Only `a`; the others are ignored
जवाब देखें

जवाब: `a` first, then `b`, then `c`

pipe reads left to right; compose reads right to left.

पाठ: Function Composition and Pipelines

11. Why put the data argument last in curried helpers?

  1. So that the function becomes impure
  2. Because JavaScript requires it
  3. To make functions run faster
  4. So that fixing the configuration arguments yields unary functions ready to compose
जवाब देखें

जवाब: So that fixing the configuration arguments yields unary functions ready to compose

map(square) is a function waiting for the data.

पाठ: Currying and Partial Application

12. Why does `["1","2","3"].map(parseInt)` misbehave?

  1. parseInt is not a function
  2. map also passes the index, which parseInt treats as the radix
  3. map skips the first element
  4. Strings cannot be mapped
जवाब देखें

जवाब: map also passes the index, which parseInt treats as the radix

Point-free passing forwards every argument the caller supplies.

पाठ: Point-Free Style and Its Limits

Recursion and Laziness

13. Why can deep recursion fail in Node.js even when written tail-recursively?

  1. Node.js forbids recursion
  2. V8 does not implement tail-call optimisation, so each call still uses a stack frame
  3. Tail calls are a syntax error
  4. Recursion is always slower than a network call
जवाब देखें

जवाब: V8 does not implement tail-call optimisation, so each call still uses a stack frame

Use loops or an explicit stack for unbounded depth.

पाठ: Recursion versus Iteration

14. What does lazy evaluation make possible?

  1. Avoiding the need for functions
  2. Guaranteed faster code in every case
  3. Running side effects in a predictable order
  4. Working with infinite sequences and stopping as soon as enough results exist
जवाब देखें

जवाब: Working with infinite sequences and stopping as soon as enough results exist

Work happens on demand.

पाठ: Lazy Evaluation, Generators and Iterators

15. Why must a memoised function be pure?

  1. Otherwise the cached result may be wrong for later calls with the same arguments
  2. Because caches only accept numbers
  3. Because pure functions cannot be called twice
  4. Because memoisation removes the function
जवाब देखें

जवाब: Otherwise the cached result may be wrong for later calls with the same arguments

Caching assumes same input, same output.

पाठ: Memoisation

Types for Functional Programming

16. What is a sum type?

  1. A number type used for addition
  2. A record that holds several fields at once
  3. A value that is exactly one of several tagged alternatives
  4. A list of all possible values
जवाब देखें

जवाब: A value that is exactly one of several tagged alternatives

Sum = OR, product = AND.

पाठ: Algebraic Data Types

17. What does the `never` assignment in the default branch achieve?

  1. It catches network errors
  2. It makes the switch run faster
  3. It makes the compiler report an error if any variant is not handled
  4. It converts the union to a class
जवाब देखें

जवाब: It makes the compiler report an error if any variant is not handled

Only an impossible value is assignable to never.

पाठ: Pattern Matching and Exhaustiveness

18. What is the main advantage of returning Result instead of throwing?

  1. The possibility of failure is visible in the type and callers must handle it
  2. Result values cannot contain errors
  3. Throwing is not allowed in TypeScript
  4. Result makes code run in parallel
जवाब देखें

जवाब: The possibility of failure is visible in the type and callers must handle it

Errors become ordinary values.

पाठ: Option/Maybe and Result/Either

Functional Abstractions

19. Why is Promise only an analogy for a functor?

  1. Promises are synchronous
  2. Promises have no then method
  3. Promises cannot hold values
  4. It runs eagerly and auto-flattens nested promises, so it does not follow the laws strictly
जवाब देखें

जवाब: It runs eagerly and auto-flattens nested promises, so it does not follow the laws strictly

then mixes map and flatMap behaviour.

पाठ: Functors: map as a Pattern

20. What does flatMap add compared with map?

  1. It sorts the values
  2. It flattens the result when the function itself returns a wrapped value
  3. It runs the function twice
  4. It removes the need for a container
जवाब देखें

जवाब: It flattens the result when the function itself returns a wrapped value

map would nest: `Option<Option<T>>`.

पाठ: Monads Explained Practically

21. In a functional core / imperative shell design, where does the database call belong?

  1. Inside every core function
  2. In the shell, which passes loaded data into the pure core
  3. In the type definitions
  4. Nowhere; databases are not allowed in FP
जवाब देखें

जवाब: In the shell, which passes loaded data into the pure core

The core decides; the shell performs.

पाठ: Functional Core, Imperative Shell

Functional Programming in Practice

22. Which feature does Elixir provide for building pipelines?

  1. The `never` type
  2. The `?` operator
  3. Java Streams
  4. The `|>` pipe operator
जवाब देखें

जवाब: The `|>` pipe operator

Elixir pipes the previous result into the next call as its first argument.

पाठ: FP in Popular Languages and Libraries

23. What must a Redux or useReducer reducer avoid?

  1. Mutating the existing state and performing side effects
  2. Returning a new object
  3. Using a switch statement
  4. Accepting an action argument
जवाब देखें

जवाब: Mutating the existing state and performing side effects

Reducers are pure functions of state and action.

पाठ: FP in Frontend and Data Pipelines

24. Why can `reduce` with object spread on every step be slow?

  1. Spread syntax runs network requests
  2. reduce is not optimised by engines
  3. It copies the whole accumulator each iteration, making the work quadratic
  4. Objects cannot be returned from reduce
जवाब देखें

जवाब: It copies the whole accumulator each iteration, making the work quadratic

Copying grows with the accumulator size.

पाठ: Trade-offs and Performance Pitfalls

25. Which item belongs on a functional programming review checklist?

  1. Reducers read the current time directly
  2. Every function mutates a shared global for speed
  3. Expected failures are returned as Result or Option values
  4. Deep-clone the whole state on every update
जवाब देखें

जवाब: Expected failures are returned as Result or Option values

Make failure explicit and keep logic pure.

पाठ: A Functional Programming Checklist

← कोर्स पर वापस जाएँ