JavaScriptCall Function (arg1) (arg2)

I am 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 type of keyword for google to search for souls. Can you please advise me what is the name of this template or how can it be implemented in JavaScript?

0
source share
2 answers

You can do:

function say(firstword){
    return function(secondword){
     return firstword + " " + secondword;   
    }
}

http://jsfiddle.net/o5o0f511/


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

Here are some more examples of this template:

How do JavaScript closures work?

+4
source

Perhaps you can try closing:

var say = function(a) {//<-- a, "Hello"
  return function(b) {//<-- b, "World"
    return a + " " + b;
  };
};

alert(say("Hello")("World")); //<--  "Hello World"

, say("Hello"), . ("World") , "Hello World"

+4

Source: https://habr.com/ru/post/1657543/


All Articles