Search⌘ K
AI Features

Solution Review: Pure Function

Explore the concept of pure functions in JavaScript functional programming. Understand how pure functions depend solely on inputs, avoid side effects, and always return outputs. This lesson reviews code examples to help you identify pure and impure functions, preparing you for interview questions on this topic.

Question 1: Solution review

Explanation

Pure functions are functions that take inputs and return the output value without affecting any variable outside of their scope. This means they don’t have any side effects on any of the data outside their scope. Hence, Option A is correct.

These functions must return a value, so Option B is incorrect. The return value must depend on the input arguments passed. Hence, Option C is correct.

Since Option B is incorrect, this means Option D is also incorrect.

Question 2: Solution review

In the ...

Javascript (babel-node)
let temp = 20
function func1(num) {
temp = 90
return num * temp
}
function func2(num) {
var answer = temp * num
}
function func3(num) {
return temp * 3
}
function func4(num) {
return num * 4
}

For ...