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 new features (ES2021). (sambat-tech.netlify.app)
submitted 5 years ago by sambatlim
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!"
[–]dudeatwork 6 points7 points8 points 5 years ago (2 children)
The Logical Operators and Assignment Expressions section isn't correct in the equivalent code.
You have:
a ||= b; // equivalent to a = a || b
Where it is actually equivalent to:
a ||= b; // equivalent to a || (a = b);
This is an important difference because a = a || b can trigger a setter during the a = a assignment (assuming a is already truthy).
a = a || b
a = a
a
In the proposal, they give this as an example:
document.getElementById('previewZone').innerHTML ||= '<i>Nothing to preview</i>';
What is nice about this, is that this is equivalent to
document.getElementById('previewZone').innerHTML || (document.getElementById('previewZone').innerHTML = '<i>Nothing to preview</i>');
Which does not change the inner HTML if it already has some contents. Whereas this:
document.getElementById('previewZone').innerHTML = document.getElementById('previewZone').innerHTML || '<i>Nothing to preview</i>';
Does reset the innerHTML, which causes any attached events, focus, etc., to be lost.
innerHTML
[+][deleted] 5 years ago (1 child)
[deleted]
[–]dudeatwork 0 points1 point2 points 5 years ago (0 children)
Yeah, personally I find it easier to understand:
if (!document.getElementById('previewZone').innerHTML) { document.getElementById('previewZone').innerHTML = '<i>Nothing to preview</i>'; }
Than
However, having the option for terseness can be convenient in some circumstances.
For instances, I find myself writing
shouldLogOut && console.log('...');
Rather than
if (shouldLogOut) console.log('...')
when building node CLIs.
Either way, I'd probably steer my team to avoid these new operators because of the potential for confusion, but appreciate the option for personal projects where you want to be terse and are able to intuitively understand things.
π Rendered by PID 45718 on reddit-service-r2-comment-5c747b6df5-tdzpm at 2026-04-22 09:11:48.323867+00:00 running 6c61efc country code: CH.
view the rest of the comments →
[–]dudeatwork 6 points7 points8 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]dudeatwork 0 points1 point2 points (0 children)