XJavascript.com
Toggle Menu
Home
Online Javascript Compiler
Tutorials
JavaScript Tutorials
TypeScript Tutorials
Blog
All Posts
Functional Programming in JavaScript
Assess how well you understand map,filter,reduce,and immutability.
1. Which of the following is a core principle of functional programming in JavaScript?
Mutable state
Side effects
Immutability
Imperative control flow
2. Select all examples of higher-order functions in JavaScript.
Array.prototype.map
Array.prototype.push
setTimeout
Function.prototype.bind
3. A pure function in JavaScript always returns the same output given the same input and has no side effects.
True
False
4. What term refers to the process of combining two or more functions to produce a new function?
5. Which array method is used to create a new array with all elements that pass a test implemented by the provided function?
map
filter
reduce
forEach
6. Which of the following are considered side effects in a JavaScript function?
Logging to console
Modifying a global variable
Returning a value
Fetching data from an API
7. In functional programming, it is recommended to use 'let' and 'var' to allow variables to be reassigned.
True
False
8. What is the process of breaking down a function that takes multiple arguments into a sequence of functions each taking one argument?
9. What does the 'reduce' method do in JavaScript?
Executes a function for each array element without returning a new array
Creates a new array with transformed elements
Reduces an array to a single value by accumulating results
Filters elements based on a condition
10. Which of the following are immutable data structures in JavaScript by default?
Strings
Numbers
Objects
Arrays
11. The 'forEach' method returns a new array with the results of calling a function for each element.
True
False
12. What is the name of the function that is passed as an argument to another function?
13. Which functional programming technique involves breaking down a function that takes multiple arguments into a series of functions each taking one argument?
Composition
Currying
Recursion
Memoization
14. Which of the following are benefits of using pure functions in JavaScript applications?
Easier testing
Predictable behavior
Increased side effects
Improved parallelism
15. Recursion is a functional programming technique where a function calls itself until a base condition is met.
True
False
16. What term describes a function that remembers the variables from the scope in which it was created, even after that scope has closed?
17. Which of the following is NOT a characteristic of functional programming in JavaScript?
First-class functions
Mutation of data
Function composition
Referential transparency
18. Select all methods that return a new array instead of modifying the original array.
Array.prototype.filter
Array.prototype.push
Array.prototype.map
Array.prototype.slice
19. Referential transparency means that an expression can be replaced with its value without changing the program's behavior.
True
False
20. What array method is used to apply a function against an accumulator and each element in the array to reduce it to a single value?
Reset
Answered 0 of 0 — 0 correct