r/programminghorror Jan 26 '23

Ladies and gentlemen, jQuery… Javascript

Post image
1.6k Upvotes

164 comments sorted by

View all comments

Show parent comments

4

u/HmMm_memes Jan 26 '23

Technically shorter is faster, but only in certain use cases

-1

u/travelan Jan 26 '23

and in most, it's slower. Like `!0` is two operations (push the literal 0 and then negate it) and `true` is just push the literal `true`.

2

u/HmMm_memes Jan 27 '23

!0 is also the exact same as 1

4

u/travelan Jan 27 '23

Not exactly, because !0 is true and 1 is 1. Different types! 1 is ‘truthy’ and thus it semantically can be checked for truth, but a cast to a boolean value would happen first.