Versatile Add

We'll cover the concepts of scope, closures, callbacks, and value vs. reference in this unique problem. This problem tests your understanding of the core concepts of JavaScript.

Introduction

In this problem, we’ll write a simple function that adds two numbers. The challenge present is that this function will have to be extremely versatile.

This problem will test your understanding of:

  • scope
  • callbacks
  • closures
  • value vs. reference

If you understand these concepts well, this problem can still be extremely difficult, but you have the ability to solve it.

Let’s get started.

Instructions

Write a function that adds 2 numbers. It should work as follows:

add(3, 4); // -> 7
add(10, 12); // -> 22

However, it should also work as follows:

add(3)(4); // -> 7
add(10)(12); // -> 22

BONUS:

Make the following lines of code also ...

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.