Skip to content Skip to sidebar Skip to footer

Javascript Functioncall(arg1)(arg2)

I'm learning JavaScript and I found this example say('Hello')('World'); This code should return 'Hello World'. I don't know how to implement this even what keyword type to googl

Solution 1:

You could do:

functionsay(firstword){
    returnfunction(secondword){
     return firstword + " " + secondword;   
    }
}

http://jsfiddle.net/o5o0f511/


You would never do this in practice though. I'm sure this is just to teach you how functions can return executable functions.

There's some more examples of this pattern here:

How do JavaScript closures work?

Post a Comment for "Javascript Functioncall(arg1)(arg2)"