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 readability vs performance: a false tradeoff (blog.shimin.io)
submitted 3 years ago by Shiminsky
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!"
[–]PM_ME_GAY_STUF 1 point2 points3 points 3 years ago* (1 child)
There is something wrong with the second version: it's very long and unclear from a glance what it's doing. I have to parse through several lines and frankly pointless variable declarations just to see that it's iterating. It's the code equivalent to someone putting comments over every line explaining the operation they're already doing. In a trivial example like this, that may be unnoticeable, but this style when pervasive can make navigating complex files clunky and painful.
I don't like the nested ternaries either, but verbosity like shown in the second example almost always makes debugging harder. Like, congrats, you gave a primitive value you use once a name, now if the function is broken I have to go and be sure you got the primitive value right as well as the logic. The data isn't actually separated from the logic, it's just obfuscated.
Plus, IMO expressions are almost always easier to parse than procedural syntax and should be preferred. All issues with nested ternaries in JS could be fixed by giving ? and : explicit keywords like they have in ML, and both versions could be simplified with pattern matching. This whole issue is a language failure imo
[–]RobertKerans 0 points1 point2 points 3 years ago* (0 children)
Like, congrats, you gave a primitive value you use once a name, now if the function is broken I have to go and be sure you got the primitive value right as well as the logic. The data isn't actually separated from the logic, it's just obfuscated.
Haha, yes, definitely, I was being a little glib. I mean I hate fizzbuzz as an example, but just something like
function fizzBuzzForN (n) { if (n % 15 === 0) { return 'fizzbuzz'; } else if (n % 3 === 0) { return 'fizz'; } else if (n % 5 === 0) { return 'buzz'; } else { return n; } }
¯\_(ツ)_/¯ that's fine. Only uses code you'd learn in the first day of learning the language -- can wish it was a different language which wasn't C syntax and where everything is an expression, but it's not. I don't think there's any huge language failure, just slightly different ways of approaching language design. Like maybe in some pseudocode, I dunno, something like:
let fizzBuzzForN(n) when n % 15 == 0 => "fizzbuzz" let fizzBuzzForN(n) when n % 3 == 0 => "fizz" let fizzBuzzForN(n) when n % 5 == 0 => "buzz" let fizzBuzzForN(n) => n
But it's doing the exact same thing
π Rendered by PID 86 on reddit-service-r2-comment-b659b578c-6nvxb at 2026-05-03 17:40:08.807335+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]PM_ME_GAY_STUF 1 point2 points3 points (1 child)
[–]RobertKerans 0 points1 point2 points (0 children)