r/programminghorror • • May 27 '26

Javascript Destructuring strings

Post image
887 Upvotes

64 comments sorted by

View all comments

Show parent comment

7

u/iamdatmonkey May 27 '26

Array destructuring comes down to Iterators. Getting the first item of an empty iterator gives you undefined.

If the string is not empty you'll get the first character, which itself is a non empty string and therefore truthy.