this post was submitted on 07 Sep 2023
29 points (69.9% liked)

Programmer Humor

32555 readers
622 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
all 13 comments
sorted by: hot top controversial new old
[–] lastunusedusername2@sh.itjust.works 59 points 1 year ago (1 children)

It looks like it's just assigning the scope variable m to true (also false in the m=!1 case.

It's minified code and m=!0 is fewer characters than m=true.

[–] Maven@lemmy.sdf.org 10 points 1 year ago (3 children)

Well I hate that. Is there a reason m=1 wouldn't be the same thing as m=!0?

[–] Hack3900@lemdit.com 40 points 1 year ago

Types are dynamic so I think the ! operator converts int to bool in JS

[–] Heavybell@lemmy.world 30 points 1 year ago

1 is truthy, but not the exact same thing as true, and the distinction can be important.

[–] InvertedParallax@lemm.ee 8 points 1 year ago (1 children)

1 != true, 1 is an int, true is a boolean

[–] WIPocket@lemmy.world 47 points 1 year ago

!0 is shorter than true, !1 is shorter than false. You are looking at minified javascript.

[–] relevants@feddit.de 42 points 1 year ago* (last edited 1 year ago)

It's not code anyone is supposed to read or work with, this is the result of minifying it to be as short as possible. And from a quick glance what's happening is that a variable is set to correspond with whether the cursor is currently over a certain element. Not sure what's funny about this?

[–] fubo@lemmy.world 25 points 1 year ago

A blurry chunk of screenshot that someone bled on, that's what.

[–] FooBarrington@lemmy.world 14 points 1 year ago (1 children)

You can go one step further and use the Bang-Bang operator:

!!m

To be read as "Bang! Bang! You're a boolean now!"

[–] alokir@lemmy.world 2 points 1 year ago (1 children)

I might be in the minority but I prefer to do it like this: Boolean(m).

It's the same thing but less cool. On the flip side it's easier to read when you have a line full of operators.

[–] FooBarrington@lemmy.world 6 points 1 year ago

Yep, that's a much better way! It's like the "goes down to" operator - a neat trick you should never use :)

while (i --> 0) { ... }

[–] grumpyrico@lemmy.world 13 points 1 year ago

Right now ... You're looking at my comment