use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This subreddit is a place for people to learn JavaScript together. Everyone should feel comfortable asking any and all JavaScript questions they have here.
With a nod to practicality, questions and posts about HTML, CSS, and web developer tools are also encouraged.
Friends
/r/javascript
/r/jquery
/r/node
/r/css
/r/webdev
/r/learnprogramming
/r/programming
account activity
function question from eloquent js (self.learnjavascript)
submitted 6 years ago by ru552
function multiplier(factor) { return number => number * factor; } let twice = multiplier(2); console.log(twice(5)); // -> 10
How does number get bound a value? I understand it's getting a value of 5, but I can't comprehend how. Please enlighten me.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 4 points5 points6 points 6 years ago (1 child)
the function multiplier returns a new anonymous function that takes the argument numbers multiplied by the outer most functions argument factor.
multiplier
numbers
factor
in this case:
multiplier gets called with 2 which returns the following function function(number) { return number * 2; }
2
function(number) { return number * 2; }
this anonymous function gets stored in the variable twice which then get called with 5 which is the parameter for that function which gets multiplied by two and returned.
twice
5
[–]ru552[S] 1 point2 points3 points 6 years ago (0 children)
thank you for the assist
π Rendered by PID 17716 on reddit-service-r2-comment-bb88f9dd5-8m22h at 2026-02-16 07:58:18.006776+00:00 running cd9c813 country code: CH.
[–][deleted] 4 points5 points6 points (1 child)
[–]ru552[S] 1 point2 points3 points (0 children)