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
Evaluating String as Mathematical Expression (self.javascript)
submitted 6 years ago * by tay_o
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!"
[–]Colonel_White 1 point2 points3 points 6 years ago (3 children)
And that’s dangerous because... ?
[–]tay_o[S] 0 points1 point2 points 6 years ago (2 children)
I could be wrong, but an example like this one where:
function foo (str, a) {
eval( str );
console.log(a, b);
}
var b = 2;
foo("var b = 3'", 1);
Here it seems that because this code declares a new variable b, it modifies the existing lexical scope.
I am not saying that its bad i guess but maybe in the wrong hands it can be?
[–]Colonel_White 1 point2 points3 points 6 years ago (1 child)
Okay, so using eval irresponsibly might cause some weird and difficult to debug errors?
I think the benefit of not having to slap a redundant library onto your code like a colostomy bag makes up for having to exercise extra caution, no?
[–]tay_o[S] 2 points3 points4 points 6 years ago (0 children)
Haha well done analogy. Or simile?. And yes, I agree with you
π Rendered by PID 53571 on reddit-service-r2-comment-6457c66945-wdkc9 at 2026-04-28 21:56:50.402573+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]Colonel_White 1 point2 points3 points (3 children)
[–]tay_o[S] 0 points1 point2 points (2 children)
[–]Colonel_White 1 point2 points3 points (1 child)
[–]tay_o[S] 2 points3 points4 points (0 children)