All quizzesEasy
Pure Functions & Immutability
Preview — 3 of 10 questions
What best describes first-class functions in JavaScript?
javascript
const add = function(a, b) {
return a + b;
};AFunctions can only be used inside classes.
BFunctions can be passed as arguments, returned from other functions, and assigned to variables.
CFunctions can only be used in the global scope.
DFunctions can only return numbers.
Which of the following is an example of a higher-order function?
javascript
function map(array, callback) {
const result = [];
for (let i = 0; i < array.length; i++) {
result.push(callback(array[i]));
}
return result;
}
map([1, 2, 3], function(x) {
return x * 2;
}); // [2, 4, 6]AA function that returns a number.
BA function that takes another function as an argument or returns a function.
CA function that does not return anything.
DA function that performs simple arithmetic operations.
What will the following code output?
javascript
function add(x, y) {
return x + y;
}
function calculate(fn, a, b) {
return fn(a, b);
}
console.log(calculate(add, 2, 3));A5
B6
Cundefined
DError
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.