Is this really possible.
Yes.
function a(x) { // <-- function
function b(y) { // <-- inner function
return x + y; // <-- use variables from outer scope
}
return b; // <-- you can even return a function.
}
console.log(a(3)(4));
More Related Contents:
- Javascript “this” pointer within nested function
- Return value from nested function in Javascript [duplicate]
- How do JavaScript closures work?
- Set a default parameter value for a JavaScript function
- What is the scope of variables in JavaScript?
- JavaScript check if variable exists (is defined/initialized)
- Pass a JavaScript function as parameter
- Returning Chrome storage API value without function
- Accessing nested JavaScript objects and arrays by string path
- Can you bind ‘this’ in an arrow function?
- How does the Math.max.apply() work?
- Calling dynamic function with dynamic number of parameters [duplicate]
- JavaScript check if variable exists (is defined/initialized)
- How to extend Function with ES6 classes?
- Advanced JavaScript: Why is this function wrapped in parentheses? [duplicate]
- JavaScript ES6: Test for arrow function, built-in function, regular function?
- Where should functions in function components go?
- Why most JavaScript native functions are slower than their naive implementations?
- onsubmit multiple javascript functions
- Why can’t I set a JavaScript function’s name property?
- How to create javascript delay function [duplicate]
- Javascript: Creating Functions in a For Loop
- Get values from an object in JavaScript [duplicate]
- setTimeout not working inside forEach
- How do I call a function inside of another function?
- What is the purpose of this? (function ($) { //function code here })(jQuery);
- How to Call a Function inside a Render in React/Jsx
- Passing parameters to a JQuery function
- jQuery asynchronous function call, no AJAX request
- What is the difference between onClick=”javascript: function(‘value’)'” and onClick=”function(‘value’);”? [duplicate]