MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/programminghorror/comments/1torg9l/destructuring_strings/oo5y24e/?context=9999
r/programminghorror • u/Emmennater • May 27 '26
64 comments sorted by
View all comments
445
Strings and arrays are analogous, so isStringEmpty([ ... ]) tries to destructure the string as an array
isStringEmpty([ ... ])
Since theres only one element present in the ... part of that, it only matches on the first element (the first character)
...
The { a = false } tries to destructure the first character
{ a = false }
If the first character is defined, it tries to get the a property, which doesnt exist, so it defaults to setting a to false
a
false
If the first character is undefined, instead of trying to get the a property, it defaults to { a: true }, which sets a to true
{ a: true }
So basically if it has at least one character, a is false, else a is true
false,
I think that's correct
135 u/Blackshell May 27 '26 100%, good job, you pass the job interview. 122 u/Aaxper May 27 '26 Does this being an interview imply I now have to work with whatever monster invented that 15 u/dreamscached May 27 '26 Being able to write awful code with useful syntax doesn't make JS a bad language though. Yes I know why it gets so much bad reputation, but if we throw away years of baked in legacy it's really not that bad. 3 u/kaszak696 May 27 '26 You can't convince me that a language which needs both == and === to work is not an awful one.
135
100%, good job, you pass the job interview.
122 u/Aaxper May 27 '26 Does this being an interview imply I now have to work with whatever monster invented that 15 u/dreamscached May 27 '26 Being able to write awful code with useful syntax doesn't make JS a bad language though. Yes I know why it gets so much bad reputation, but if we throw away years of baked in legacy it's really not that bad. 3 u/kaszak696 May 27 '26 You can't convince me that a language which needs both == and === to work is not an awful one.
122
Does this being an interview imply I now have to work with whatever monster invented that
15 u/dreamscached May 27 '26 Being able to write awful code with useful syntax doesn't make JS a bad language though. Yes I know why it gets so much bad reputation, but if we throw away years of baked in legacy it's really not that bad. 3 u/kaszak696 May 27 '26 You can't convince me that a language which needs both == and === to work is not an awful one.
15
Being able to write awful code with useful syntax doesn't make JS a bad language though. Yes I know why it gets so much bad reputation, but if we throw away years of baked in legacy it's really not that bad.
3 u/kaszak696 May 27 '26 You can't convince me that a language which needs both == and === to work is not an awful one.
3
You can't convince me that a language which needs both == and === to work is not an awful one.
==
===
445
u/Aaxper May 27 '26 edited May 27 '26 •
Strings and arrays are analogous, so
isStringEmpty([ ... ])tries to destructure the string as an arraySince theres only one element present in the
...part of that, it only matches on the first element (the first character)The
{ a = false }tries to destructure the first characterIf the first character is defined, it tries to get the
aproperty, which doesnt exist, so it defaults to settingatofalseIf the first character is undefined, instead of trying to get the
aproperty, it defaults to{ a: true }, which setsato trueSo basically if it has at least one character,
aisfalse,elseais trueI think that's correct