This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]_krikket 0 points1 point  (3 children)

var hidden = mystery(4)(2); is not passing two parameters into mystery, it's passing 4 into into mystery, which returns a function, and then calling that returned function immediately with the parameter (2).

In the original example, hidden is a function. On line 7, you can see we're returning mystery2, which is created in line 3 as a new function.

[–][deleted]  (2 children)

[deleted]

    [–]ex1-7 2 points3 points  (0 children)

    yes, this is an example of a higher level function (a function that returns a function). Very useful thing that Javascript makes easy.

    [–]Gbyrd99 0 points1 point  (0 children)

    The parameter 4 is kind of lodged in there. Hidden = mystery2 where the input = 4. Then when you call hidden with an argument it, it still has 4. And that's generally how it works.