Question About How JavaScript "Knows" Implicit Things

Hi, so I have a question dealing with something that I’ve been curious about off and on for some time now. In the below example, the curried functions seem to automatically be known to JavaScript to be x, y, z as they appear in the add function on execution.

How does JavaScript “know” to interpret or know to feed to the interpreter that 10 = x, 20 = y, and 30 = z?

Is it simply the order in which the add function parameters are in left-to-right and the curried functions in from top-to-bottom?

Thank you in advance for reading/answering my post.

function add(x) {
  // Add your code below this line
  return function(y) {
    return function(z) {
      return x + y + z;
  // Add your code above this line

If you do var x = add(10), x now will have the value of `

  function(y) {
    return function(z) {
      return 10 + y + z;

Similarly, if you do var y = x(20), y will have the value of

   function(z) {
     return 10 + 20 + z;

So on…

So basically add(10)(20)(30) is the same as

var x = add(10)

var y = x(20)

var z = y(30)

I hope this makes sense to you.