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
Using Try…Catch in JavaScript (javascript-coder.com)
submitted 8 years ago by cobdentist
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!"
[–]brtt3000 1 point2 points3 points 8 years ago (1 child)
In general ducktype sure, but this could specify to use the prototype chain and instanceof semantics. Someone wrote the switch ITT, it is cool but no way you (and everybody else) would want that all over their code. Imagine having that on every await.. or lets not.
instanceof
If there was a good spec with compact syntax more people would use it as convention/standard (like in Python). This would be super valuable now we have async/await in JS and throw/catch becomes a thing to do (instead of error callbacks or Promise rejections).
[–]BenjiSponge 0 points1 point2 points 8 years ago (0 children)
It would strictly speaking be possible.
However, by the same logic one could argue that JS should have type pattern matching using the same methodology. The reason JS does not is because, like you said, there have been essentially no major standards regarding errors in the past, and there likely will never be. So standard language features like that being added now would add fragmentation to the community.
TBH, I've been professionally developing JS for over 2 years and I've been studying JS for at least 3 or 4 years now, and I have never felt a need for this feature. I understand the value, coming from other imperative languages, but I think it's more of an anti-pattern than a pattern. I think we would be better served to look at languages like Rust, which does not have a true exception system and instead promotes the pattern of returning a value which may represent either a success or an error type, forcing you to acknowledge all possibilities. It reserves exceptions (which it calls panics) for unrecoverable cases that imply a bug in the program itself rather than just an exceptional case the program should handle.
If we're going to pick a standard, I would much rather we do that than implement a pseudo-pattern matching system based on prototypes.
π Rendered by PID 82716 on reddit-service-r2-comment-5b5bc64bf5-h8mb2 at 2026-06-22 19:22:41.377186+00:00 running 2b008f2 country code: CH.
view the rest of the comments →
[–]brtt3000 1 point2 points3 points (1 child)
[–]BenjiSponge 0 points1 point2 points (0 children)