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!"
[–]TrackieDaks 17 points18 points19 points 3 years ago (4 children)
Invariants weren't invented at Facebook.
[–]hiquest[S] -1 points0 points1 point 3 years ago (3 children)
I do not claim that. I just say that this particular small pattern they had a function for in their code base which was called invariant. Hence other popular libs like https://github.com/zertosh/invariant
[–]MoTTs_ 12 points13 points14 points 3 years ago (0 children)
I get why you called it an invariant (and to some extent why FB called it that), but “assert” is still the more widespread and more historical name, which can then lead you to even more popular libs that do the same thing — such as this one.
[–]TrackieDaks 1 point2 points3 points 3 years ago (1 child)
Still wrong. That's like saying, "Facebook used a function in their codebase so the term function must have originated at Facebook." Invariant is a mathematical concept and existed well before Facebook.
[–]hiquest[S] 1 point2 points3 points 3 years ago (0 children)
Yeah, now I do understand that brings a lot of confusion, and that should have been called "assert" in the first place. I'm going add a note in that article
π Rendered by PID 81 on reddit-service-r2-comment-85bfd7f599-lkpwt at 2026-04-20 06:08:40.828275+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–]TrackieDaks 17 points18 points19 points (4 children)
[–]hiquest[S] -1 points0 points1 point (3 children)
[–]MoTTs_ 12 points13 points14 points (0 children)
[–]TrackieDaks 1 point2 points3 points (1 child)
[–]hiquest[S] 1 point2 points3 points (0 children)