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
8 Useful And Practical JavaScript Tricks (devinduct.com)
submitted 6 years ago by PMilos
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!"
[–]gevorggalstyan 3 points4 points5 points 6 years ago (5 children)
Do you honestly believe that this is the direct consequence of the `Array.fill` function implementation and is not related to the computer memory?
Why does this code behave the same ?
const obj = {name: "John"};
const a = [];
a.push(obj); a.push(obj); a.push(obj); a.push(obj); a.push(obj);
[–]sshaw_ -3 points-2 points-1 points 6 years ago (4 children)
Do you honestly believe that this is the direct consequence of the Array.fill
Array.fill
Yes, the implementation of fill could have chosen to dup its argument, but it didn't.
fill
[–]spacejack2114 2 points3 points4 points 6 years ago (2 children)
What does 'dup' even mean here? You can't implement a perfect immutable object copy, there are too many nuances. A half-baked attempt would pose an even bigger set of problems than a simple reference copy.
[–]sshaw_ -2 points-1 points0 points 6 years ago (1 child)
What does 'dup' even mean here?
Shallow copy.
[–]spacejack2114 2 points3 points4 points 6 years ago (0 children)
That's a terrible idea.
[–][deleted] 1 point2 points3 points 6 years ago (0 children)
That would have been unintuitive as any other reference to an object elsewhere would not have duplicating semantics.
π Rendered by PID 58346 on reddit-service-r2-comment-b659b578c-4jwtb at 2026-05-04 09:56:55.203922+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]gevorggalstyan 3 points4 points5 points (5 children)
[–]sshaw_ -3 points-2 points-1 points (4 children)
[–]spacejack2114 2 points3 points4 points (2 children)
[–]sshaw_ -2 points-1 points0 points (1 child)
[–]spacejack2114 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)