curriculum/challenges/english/blocks/quiz-javascript-functional-programming/66edd4f31ff19bf5573bf64b.md
To pass the quiz, you must correctly answer at least 9 of the 10 questions below.
What is a pure function?
A function that modifies global variables and returns either undefined or null.
A function that logs an output to the console.
A function that changes its behavior based on external factors and returns null.
A function that always returns the same output for the same input and produces no side effects.
What is a side effect in functional programming?
An unexpected TypeError in your code.
A function that takes too long to execute and crashes the program.
A recursive function call that produces an infinite loop and crashes the program.
A change to the state of the program that are observable outside the function.
What is currying in functional programming?
A technique for designing tests to help you ensure your code is 100% error free.
A more optimized way to write recursive functions so they run twice as fast as other functions.
The process of building, designing and testing your code to ensure that it meets the standards laid out by ECMAScript.
The process of transforming a function with multiple arguments into a sequence of functions, each with a single argument.
What will be the output for the following pure function?
const add = (a, b) => a + b;
console.log(add(2, 5));
3
4
undefined
7
Which of the following is an example of currying?
const curriedAverage = (a, b, c) => a + b + c / 3
const curriedAverage = (a, b, c) => a + b + c
function curriedAverage(a) {
return a
}
function curried(c) {
return c
}
function curriedAverage(a) {
return function(b) {
return function(c) {
return (a + b + c) / 3;
};
};
}
Which of the following is a key principle of functional programming?
Modifying global variables frequently.
Using mutable data structures extensively.
Emphasizing object-oriented inheritance.
Avoiding side effects and using immutable data.
What is an impure function?
A function that returns an object.
A function without side effects.
A function that returns null
A function with side effects.
Which of the following is the correct way to call a curried function?
curriedAverage(2 3 4);
curriedAverage(2)==(3)==(4);
curriedAverage(2)=>(3)=>(4);
curriedAverage(2)(3)(4);
Which of the following is an example of an impure function?
function example(num) {
return num;
}
function sum(num1, num2) {
return num1 + num2
}
function addToTotal(value) {
let total = 0;
total += value;
return total;
}
let total = 0;
function addToTotal(value) {
total += value;
return total;
}
Which of the following is NOT an example of a side effect?
Writing to a file.
Modifying a global variable.
Making an API call.
Returning the sum of two values.