Undo is to remove or reverse actions right!!!!
So why is unshift used to add to an array in JS? š
Continue the thread by commenting with yours in the comments section.
Keep it rolling
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (6)
Before, in PHP, comparing "password" == 0 used to return true.
Entire login systems got walked right through.
unshiftactually makes sense once you know it's the mirror ofshift, which is borrowed straight from Perl (and Unix shell before it).shiftpulls the first argument off$@, sounshiftputs one back on the front. The "un" isn't undo ā it's the reverse operation on the same end of the list. JS just inherited the naming wholesale.The real quirk is that
push/popandshift/unshiftreturn different things:pushgives you the new length,popgives you the removed element. So you get bugs where someone writesconst x = arr.push(y)expectingyback and gets a number instead.wowwwww, I didn't see it like that.
Yeah, JS can be crazy š« š š
in SQL:
NULL=NULLevaluates toNULL(not TRUE). Equality itself becomes uncertain.š„²
Lol. š«
DYK that
[] == ![]istruein Javascript?This reminded me that every language has its own personality. Some of these quirks seem odd at first, but they're often the things you remember the most when switching between languages. Nice post!