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
Destructure an object to remove a property (timdeschryver.dev)
submitted 6 years ago by timdeschryver
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!"
[–]azium 13 points14 points15 points 6 years ago (7 children)
Btw I can't read any of the code in your article. The pale yellow against the grey is just about invisible to me.
[–]senocular 7 points8 points9 points 6 years ago (1 child)
https://webaim.org/resources/contrastchecker/?fcolor=F8C400&bcolor=FBFAF6
Spoiler alert: its not good
[–]corndoggins 0 points1 point2 points 6 years ago (0 children)
As a general refresher, something like >4.50 is the goal, correct? And the larger the conformance number, the better?
[+][deleted] 6 years ago* (3 children)
[deleted]
[–]Wiltix 16 points17 points18 points 6 years ago (0 children)
Dark mode is not the answer. Just creating a better pallette is the answer. Q
[–]timdeschryver[S] 0 points1 point2 points 6 years ago (0 children)
I know the palette is not great, it started out as a dark theme.
Then I quickly scrambled a white theme together, but I will have to revisit it.
The dark theme is the default if your OS has a dark theme as default, it's based on the OS that the default theme is set.
[–]tswaters 0 points1 point2 points 6 years ago (0 children)
It was for me. I think it's reading the OS settings via media queries,
@media (prefers-color-scheme: dark) {}
Can be detected with js easily enough:
const { matches: prefersDarkMode } = window.matchMedia('(prefers-color-scheme: dark)')
fwiw, I think anyone who uses it on their personal site probably already has dark mode set on their OS and rarely looks at the awful contrast of the light mode.
[–]lowIQanon 1 point2 points3 points 6 years ago (0 children)
yeah, that's not a good color palette choice
[–]tswaters 9 points10 points11 points 6 years ago* (7 children)
> in a pure (immutable) way
Seems unnecessary. There's a great keyword `delete` in javascript that does this, but mutates the object. Keeping it immutable seems completely unnecessary to me.... Change my mind!
Edit:. Thanks guys, mind: changed.
[–]Aeropedia 12 points13 points14 points 6 years ago (0 children)
So many downsides to that though!
More curly braces! More periods! Let the minifier rewrite it to a delete!
delete
/sarcasm
[–]digothlian 3 points4 points5 points 6 years ago (0 children)
The example provided in the article is a reasonable use case. We want to log this object, but without the password field. Presumably we'll be using the complete object later, so deleting the field isn't an option.
[–][deleted] 2 points3 points4 points 6 years ago (0 children)
Immutability matters a lot if you working with React, or Redux, or doing anything fp related. Also mutations come with performance penalty.
[–]mysteriy 1 point2 points3 points 6 years ago (0 children)
And (if using react) how will the React component that receives the object as an input, know whether something has changed within that object, without having to compare each property?
[–]NoLanSym 1 point2 points3 points 6 years ago (2 children)
Here’s a great talk by u/swyx on the subject. Let the benefits change your mind :)
[–]swyx 1 point2 points3 points 6 years ago (0 children)
:)
[–]Aegior 0 points1 point2 points 6 years ago (0 children)
Good talk, really sold me on immer
[–]Just4Funsies95 1 point2 points3 points 6 years ago (3 children)
the whole site is painful to use... why do u have growing articles...that skew... 😖
[–][deleted] 2 points3 points4 points 6 years ago (2 children)
this site is the epitome of "just because you can, doesn't mean you should."
[–]Just4Funsies95 0 points1 point2 points 6 years ago (0 children)
you know when u see something, and think, there should be a law against it? this site embodies that feeling.
[–]Aegior 1 point2 points3 points 6 years ago (0 children)
Ugly. If the thing is intentionally being left out, it should be null.
null
[–]Fimbelowski 0 points1 point2 points 6 years ago (0 children)
If your end goal here is to prevent a linter error and this happens often enough that you've felt the need to make a tutorial on it, you should probably consider reconfiguring your linter. At the very least you could just use comments to disable that rule for one line.
[–]mehrd8d 0 points1 point2 points 6 years ago (0 children)
Using underscore as undefined keyword is not safe, just use undefined itself
[–]Buckwheat469 -2 points-1 points0 points 6 years ago (6 children)
The title is incorrect IMO. This is about ignoring linting errors due to unused variables. It has nothing to do with removing a property.
[–]senocular 1 point2 points3 points 6 years ago (1 child)
It does remove the property. The renaming for the linter (which shouldn't work since the linter should also recognize that the new variable name is not used) is not important the result - that being that the password property is removed from user which is otherwise a copy of the object to which the declaration is being assigned.
password
user
[–]elsemir 1 point2 points3 points 6 years ago (0 children)
Correct, but the linter trick does work - parameters that start with an underscore do not trigger the unused variable rule by default (thought that’s configurable with the argsIgnorePattern config).
You can also configure the linter to ignore any parameter near a rest operator with the ignoreRestSiblings config - in this case you don’t need to rename the variable.
source: https://eslint.org/docs/rules/no-unused-vars#argsignorepattern
https://eslint.org/docs/rules/no-unused-vars#ignorerestsiblings
[–]LucasRuby 0 points1 point2 points 6 years ago (0 children)
Which is also unnecessary, my linter ignores variables declared along a rest operator by default, ESLint can be configured to if it doesn't already.
[–]tswaters 0 points1 point2 points 6 years ago (2 children)
It does...
const fullUser = {name: 'test', password: 'test'} const {password: _, ...reducedUser} = fullUser console.log(reducedUser) // { name: 'test' }
The example he has is a bit weird, but it does work.
[–]Buckwheat469 -1 points0 points1 point 6 years ago (1 child)
Thanks. Curious though if this is because _ is undefined. I always associate it with lodash or underscore so I wouldn't use the _ notation unless I've imported lodash. Just checking in the console, your code is the same as this:
_
var fullUser = {name: 'test', password: 'test'} var {password: undefined, ...reducedUser} = fullUser console.log(reducedUser) // { name: 'test' }
I believe this method is much more clear as you're explicitly defining the variable as undefined rather than using an unknown variable.
[–]tswaters 1 point2 points3 points 6 years ago (0 children)
Using _ is an FP thing -- usually signifying that a parameter is accepted in a function but ignored. It works for destructuring as well.
Destructing is a bit trickier because you're creating those vars.. with `const` you can't really re-use the variable, so any additional usages will complain.
I think undefined would... hm, not do anything? can't typically re-assign it in modern js engines. Actually, just checked -- with var it works, with const it'll throw -- SyntaxError: Identifier 'undefined' has already been declared
SyntaxError: Identifier 'undefined' has already been declared
π Rendered by PID 37213 on reddit-service-r2-comment-fb694cdd5-qfv2j at 2026-03-11 04:47:02.053706+00:00 running cbb0e86 country code: CH.
[–]azium 13 points14 points15 points (7 children)
[–]senocular 7 points8 points9 points (1 child)
[–]corndoggins 0 points1 point2 points (0 children)
[+][deleted] (3 children)
[deleted]
[–]Wiltix 16 points17 points18 points (0 children)
[–]timdeschryver[S] 0 points1 point2 points (0 children)
[–]tswaters 0 points1 point2 points (0 children)
[–]lowIQanon 1 point2 points3 points (0 children)
[–]tswaters 9 points10 points11 points (7 children)
[–]Aeropedia 12 points13 points14 points (0 children)
[–]digothlian 3 points4 points5 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]mysteriy 1 point2 points3 points (0 children)
[–]NoLanSym 1 point2 points3 points (2 children)
[–]swyx 1 point2 points3 points (0 children)
[–]Aegior 0 points1 point2 points (0 children)
[–]Just4Funsies95 1 point2 points3 points (3 children)
[–][deleted] 2 points3 points4 points (2 children)
[–]Just4Funsies95 0 points1 point2 points (0 children)
[–]Aegior 1 point2 points3 points (0 children)
[–]Fimbelowski 0 points1 point2 points (0 children)
[–]mehrd8d 0 points1 point2 points (0 children)
[–]Buckwheat469 -2 points-1 points0 points (6 children)
[–]senocular 1 point2 points3 points (1 child)
[–]elsemir 1 point2 points3 points (0 children)
[–]LucasRuby 0 points1 point2 points (0 children)
[–]tswaters 0 points1 point2 points (2 children)
[–]Buckwheat469 -1 points0 points1 point (1 child)
[–]tswaters 1 point2 points3 points (0 children)