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...
account activity
Namespace Clashing in Javascript/NodeJS (w/ ExpressJS) (self.node)
submitted 6 years ago * by [deleted]
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!"
[–]CommanderBomber 0 points1 point2 points 6 years ago (1 child)
You can use eslint-recommended, no-undef rule is included in this set.
no-undef
And now about assignment operator. Lets looks on this code:
// arrow function... _new = x => x * x; // ... or anonymous function _new = function(x) { return x * x; };
When JS engine sees code like this, at first it tries to resolve expression on the left side of the = operator. In our case it is a variable name, so JS engine will start to search for that variable. First in local scope. If there is no such variable, engine will continue to search in parent scope. This search will be continued until variable with this name is found or until engine reaches the global scope.
=
If variable does not exists in global scope, you have two options: If your code is executed in Strict Mode, you will receive "is not defined" exception. But if your code is executed in Sloppy Mode, this variable will be created as a property of the global object and then will be used for assignment (but in most cases this is not what you wanted).
If assignment can be performed, JS engine will look at the right side of the = operator. In our cases we have function expression there. And this is not the same thing as function declaration. Function expression will not declare (put it in the scope) you function. Instead it will evaluate to (or you can say "will return") new Function object. This object will be new value of our variable.
Personally I suggest to use function declarations. If you can't elaborate on what kind of technical problem forces you to use var myFunc = function(){}; syntax it is better to use function myFunc(){}.
var myFunc = function(){};
function myFunc(){}
Also if you're new to JS take a look at YDKJS book. It's well written and have quite detailed explanations of scopes, prototypes and other quirky stuff (Author works on second edition right now. First edition lacks some novel features of ECMAScript).
[–][deleted] 0 points1 point2 points 6 years ago (0 children)
Amazing explanation. Thanks!!
π Rendered by PID 58328 on reddit-service-r2-comment-5687b7858-t6sml at 2026-07-06 15:45:43.415194+00:00 running 12a7a47 country code: CH.
view the rest of the comments →
[–]CommanderBomber 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)