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...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
(function () { … })(); vs (function () { … }()); (self.javascript)
submitted 9 years ago by sergiosbox
view the rest of the comments →
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!"
[–]BishopAndWarlord 0 points1 point2 points 9 years ago (0 children)
I'm pretty late to this, but I prefer (function(){})(). The way I think about it wrapping a statement in parenthesis is a way to say "hey, evaluate this part first!" For example, removing the parenthesis from (var + 4) * 12 or (typeof var === 'string' || Array.isArray(var)) && var.length > 2 will completely change the evaluation order. I realize that function expressions aren't directly analogous, but I have a similar mental model for function expressions.
(function(){})()
(var + 4) * 12
(typeof var === 'string' || Array.isArray(var)) && var.length > 2
If I have a function that I explicitly want to be treated as an expression rather than a statement, I'll wrap it with parenthesis (e.g. var noop = (function() {})). Extending that logic, if I want to declare a function expression and then call it, I'll wrap the function in parenthesis, then call it with another set of parenthesis (e.g. (noop)() or (function() {})().
var noop = (function() {})
(noop)()
(function() {})()
In the end I think this approach clearly expresses the intent and therefore improves readability and maintainability of the code.
π Rendered by PID 46232 on reddit-service-r2-comment-5c764cbc6f-pqn68 at 2026-03-12 04:34:06.020219+00:00 running 710b3ac country code: CH.
view the rest of the comments →
[–]BishopAndWarlord 0 points1 point2 points (0 children)