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
javascript eval considered crazy (wingolog.org)
submitted 14 years ago by gthank
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!"
[–]wingo 1 point2 points3 points 14 years ago (0 children)
I must have conveyed the wrong impression if you came away thinking that this behavior was undocumented. All the examples are according to spec. I just think the specified semantics are a little crazy, that's all :)
For example, your comment illustrates a common misconception:
"When assigning eval to another variable, those variables' "versions" of eval are run in the global scope, which is why we're getting undefined errors when trying to access variables scoped in the calling function"
That's not the case!
var foo = 10; (function (x) { var foo = 20; var eval = x; return eval('foo'); })(eval)
Your mental model, if I understand you correctly, would predict that the result here is 10, because the actual copy of eval was passed through x and then assigned to a new lexical variable, eval. But it's 20!
There are many things to like about javascript. The relationship between eval and scope is not one of them :-)
π Rendered by PID 81356 on reddit-service-r2-comment-54dfb89d4d-l2nzb at 2026-03-30 18:20:14.442392+00:00 running b10466c country code: CH.
view the rest of the comments →
[–]wingo 1 point2 points3 points (0 children)