Question 24
What is the output of the following code?
Solution
By guessing, you could imply 5 * 28 = 140 and simply pick the answer from there.
Realistically, perimeter() becomes a circumference function if sides = 0, a normal perimeter function for all regular polygons if sides = 3, and returns 0 otherwise.
Either one of the circumference or regular polygon perimeter function then takes one parameter each to use for calculating its respective values.
Here, this means that perimeter(5) becomes a perimeter function for all regular polygons.
By passing 28 into this function, perimeter(5)(28) leads to l = 28 and hence it returns l * sides = 28 * 5 = 140.