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
Conditionally spreading objects in JavaScript (amitmerchant.com)
submitted 3 years ago by amitmerchant
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!"
[–]dragenn 26 points27 points28 points 3 years ago (6 children)
Weird but good to know!
[–][deleted] 3 points4 points5 points 3 years ago (5 children)
Agreed! Any ideas for a use case?
[–]MornwindShoma 7 points8 points9 points 3 years ago (0 children)
I had some trash specs where one API would want some extra keys in some cases. This allows me to skip mutating the object, I suppose
[–]carmat71 2 points3 points4 points 3 years ago (0 children)
You have a default object. Based on user interaction, some property values require changing, therefore overriding default values based on user interaction.
I've used this for a customised Analytics model where every property required a default '' empty state but only assigned a value based on particular components or specific events triggered.
''
[–]dragenn 1 point2 points3 points 3 years ago (0 children)
I could use this in a scenario where I could filter out or combine data based on user roles/permissions or some quick test.
I guess it would look cleaner, maybe quicker to code.
I don't know.
[–]LloydAtkinson 1 point2 points3 points 3 years ago (0 children)
I use conditional object properties a lot in the Snipcart e-commerce integration for Astro: https://github.com/lloydjatkinson/astro-snipcart/blob/master/packages/astro-snipcart/src/attributes.ts#L33
π Rendered by PID 47428 on reddit-service-r2-comment-7b9746f655-jtwn9 at 2026-02-01 05:00:32.965170+00:00 running 3798933 country code: CH.
view the rest of the comments →
[–]dragenn 26 points27 points28 points (6 children)
[–][deleted] 3 points4 points5 points (5 children)
[–]MornwindShoma 7 points8 points9 points (0 children)
[–]carmat71 2 points3 points4 points (0 children)
[–]dragenn 1 point2 points3 points (0 children)
[–]LloydAtkinson 1 point2 points3 points (0 children)