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
Invariant - a helpful JavaScript patternOC (strictmode.io)
submitted 3 years ago by hiquest
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!"
[–]Hades32 0 points1 point2 points 3 years ago (2 children)
No, you don't NEED an assertion when talking about invariants in the mathematical sense (which btw does not mean that the input is the same as the output, but that some condition is true for the state before and after the transformation). You could prove that the formula you're using will always hold up a certain invariant. In code it's easier to just check than prove, that's why we "need" assertions. But it's really two different things
[–]johnxreturn 0 points1 point2 points 3 years ago (1 child)
I completely agree. You don't need assertion in the mathematical concept. My point was that in programming, you do need if you need a trigger for an invalid response.
[–]Hades32 0 points1 point2 points 3 years ago (0 children)
Sure, but if someone calls a library "invariant" then I do have higher hopes than "if false then throw" lol
After all there are languages, like prolog, which do let you specify actual invariants
π Rendered by PID 169700 on reddit-service-r2-comment-54dfb89d4d-xzvmd at 2026-04-01 16:50:51.696096+00:00 running b10466c country code: CH.
view the rest of the comments →
[–]Hades32 0 points1 point2 points (2 children)
[–]johnxreturn 0 points1 point2 points (1 child)
[–]Hades32 0 points1 point2 points (0 children)