597
Thdpsssps (thelemmy.club)
submitted 1 day ago* (last edited 1 day ago) by Stefan_S_from_H@piefed.zip to c/microblogmemes@lemmy.world
you are viewing a single comment's thread
view the rest of the comments
[-] python@lemmy.world 5 points 22 hours ago

Javascript would have no problem with it. Semicolons are already kinda optional in there, and having tons of question marks in your code is also pretty normal. ie:

input?.map(item => !!item?.name ? item : item?.toString() ?? "New Item")

Just means: If the variable named "input" has a function named .map(), which is usually the case if it's an array, you go through that array and transform its elements in the following way:

  • is your element an object that has the property "name" and that property isn't undefined, null or 0? (the "!!" is a double negation that would force undefined, null and 0 to evaluate to false through type coercion)?

  • if yes ( the syntax " ___ ? ___ : ___ " is a shorthand for an if-else statement) then just add that whole item to your output array.

  • if not, try to call the .toString() function on your item. If that works then that's your result, if not then your output is the string "New Item" ( the "??" is called the nullish coalescing operator - if the left side of the ?? evaluates to undefined or null, it takes the right--hand side value instead. The "?." part is called optional chaining and will evaluate to undefined if you try to call a function that doesn't exist on that type)

  • oh yeah, and if input isnt an array to begin with and doesn't have a .map() function? We just do nothing and move on without complaining. JS truly does not give a fuck.

[-] dave@feddit.uk 5 points 21 hours ago

You missed a ‘?’ I think you meant:

input?.map?.(item => …

[-] python@lemmy.world 3 points 20 hours ago

oh, you're right lol
The first ?. after input would be more more of a safeguard against input being null/undefined and the .map not existing on it would have to have another ?.

[-] skulkbane@lemmy.world 3 points 21 hours ago

Yeah c# has null propagation and null coale aswell. But I imagen Greeks learning programming having fun with it for a little while.

this post was submitted on 04 Jun 2026
597 points (98.4% liked)

Microblog Memes

11591 readers
1342 users here now

A place to share screenshots of Microblog posts, whether from Mastodon, tumblr, ~~Twitter~~ X, KBin, Threads or elsewhere.

Created as an evolution of White People Twitter and other tweet-capture subreddits.

RULES:

  1. Your post must be a screen capture of a microblog-type post that includes the UI of the site it came from, preferably also including the avatar and username of the original poster. Including relevant comments made to the original post is encouraged.
  2. Your post, included comments, or your title/comment should include some kind of commentary or remark on the subject of the screen capture. Your title must include at least one word relevant to your post.
  3. You are encouraged to provide a link back to the source of your screen capture in the body of your post.
  4. Current politics and news are allowed, but discouraged. There MUST be some kind of human commentary/reaction included (either by the original poster or you). Just news articles or headlines will be deleted.
  5. Doctored posts/images and AI are allowed, but discouraged. You MUST indicate this in your post (even if you didn't originally know). If an image is found to be fabricated or edited in any way and it is not properly labeled, it will be deleted.
  6. Absolutely no NSFL content.
  7. Be nice. Don't take anything personally. Take political debates to the appropriate communities. Take personal disagreements & arguments to private messages.
  8. No advertising, brand promotion, or guerrilla marketing.

RELATED COMMUNITIES:

founded 2 years ago
MODERATORS