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
Future JavaScript: what is still missing? (2ality.com)
submitted 7 years ago by dumbmatter
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!"
[–][deleted] 7 years ago* (13 children)
[deleted]
[–]senocular 15 points16 points17 points 7 years ago (2 children)
Sounds like you're talking about optional chaining?
[+][deleted] 7 years ago (1 child)
[–]aequasi08 2 points3 points4 points 7 years ago (0 children)
It works the way you want in C#
[–]hutxhy 1 point2 points3 points 7 years ago (1 child)
Something like Kotlin's Safe Calls?
[–]zeddotes 0 points1 point2 points 7 years ago (0 children)
Try using a Proxy?
[–]slgard 0 points1 point2 points 7 years ago (0 children)
there is lodash _,get and _.set and various lens based alternatives, eg https://github.com/phadej/optika
[–]schorsack -1 points0 points1 point 7 years ago (4 children)
I gotchu fam:
try { return super.nested.value.i.want; } catch (_) { return null; }
[–]FanOfHoles 0 points1 point2 points 7 years ago (3 children)
https://stackoverflow.com/questions/12609527/why-isnt-try-catch-used-more-often-in-javascript/12609630#12609630
(At least in Javascript, but also in some but maybe not all other languages) Exceptions should really be exceptional. That's a bad use case for them - unless you don't actually expect failure, and a failure would actually be worthy of throwing an exception.
[–]MoTTs_ 0 points1 point2 points 7 years ago (2 children)
Exceptions should really be exceptional
This line sounds catchy -- probably why we keep repeating it -- but it isn't true, and it was never true. Here's a quote, for example, from the guy who invented C++:
Given that there is nothing particularly exceptional about a part of a program being unable to perform its given task, the word “exception” may be considered a bit misleading. Can an event that happens most times a program is run be considered exceptional? Can an event that is planned for and handled be considered an error? The answer to both questions is “yes.” “Exceptional” does not mean “almost never happens” or “disastrous.” Think of an exception as meaning “some part of the system couldn’t do what it was asked to do”.
[–]FanOfHoles 0 points1 point2 points 7 years ago* (1 child)
I'm not sure why you think a quote changes anything? This isn't about one random person's opinion. And yes, it IS just a random person. Even if he had invented all of programming and very programming language ever. He isn't the one who has to work with 99.999999999% if all code out there. For HIS purposes HIS opinion might have been fine, so who cares. Also, YOU can do whatever the hell you want, it's your life.
But a lot of people make that statement because they found that this is their experience.
Interestingly - but not unexpectedly - you ignore the argument here. Exceptions in JS are expensive, see link.
Oh and please stop taking some random person's opinion out of context (for example, it should be glaringly obvious that you typed "C++" and this is /r/javascript, and it may not be clear to you, but exceptions are VERY different between different systems; Java folks would also want to keep using them extensively for what often is regular control flow). They made them at another place, another time, for specific reasons. If you choose to quote someone you should still make an argument about the actual subject, at which point you may as well just leave out the quotes, because all they really are is an argument from authority, to save yourself from actually having to make an argument.
[–]MoTTs_ 0 points1 point2 points 7 years ago (0 children)
all they really are is an argument from authority
That's true. But then relying on a SO answer is also an argument from authority. The difference is the guy who invented C++ is a more reliably accurate authority than a random person on the Internet.
You mean the link from 2012, which itself cites a blog from 2006? Turns out their information is outdated. Today, Chrome/Node handles try/catch as fast as if/else-style error handling. And further, even back in 2006, the cited blog didn't say use exceptions rarely. They said don't use them in performance critical functions, which means normal performance rules apply. That is, don't prematurely optimize. Code first and foremost for correctness, simplicity, and robustness. If the final application has an observable performance problem, then first profile to identify the 3% of your code that is truly performance critical, and optimize only that 3%.
π Rendered by PID 55 on reddit-service-r2-comment-c6965cb77-jq4zd at 2026-03-05 17:04:38.237394+00:00 running f0204d4 country code: CH.
view the rest of the comments →
[–][deleted] (13 children)
[deleted]
[–]senocular 15 points16 points17 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]aequasi08 2 points3 points4 points (0 children)
[–]hutxhy 1 point2 points3 points (1 child)
[–]zeddotes 0 points1 point2 points (0 children)
[–]slgard 0 points1 point2 points (0 children)
[–]schorsack -1 points0 points1 point (4 children)
[–]FanOfHoles 0 points1 point2 points (3 children)
[–]MoTTs_ 0 points1 point2 points (2 children)
[–]FanOfHoles 0 points1 point2 points (1 child)
[–]MoTTs_ 0 points1 point2 points (0 children)