Facebook Pixel

How should I approach the sum(1)(2)(3) Amazon question in an interview?

Recognize it as currying. Start with the simple solution (terminate with empty call). Explain how closures accumulate the sum. Mention toString as an alternative. Handle follow-ups like multiple arguments.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in sum(1)(2)(3) Interview Tips for Amazon

Not returning a function (the chain breaks), not accumulating the previous value, no termination mechanism (no way to get the result), and overcomplicating (using classes or complex state instead of a simple closure).

Yes. After the basic solution, mention that you could also use toString or valueOf for automatic type coercion. This shows deeper JavaScript knowledge (type coercion, toString, valueOf).

Step by step: sum(1) returns a function with a=1. Calling it with 2 returns sum(3) (a new function with a=3). Each call accumulates. Calling with no argument returns the accumulated sum. Each step uses a closure.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.