this post was submitted on 25 Jan 2025
1442 points (99.0% liked)

Programmer Humor

20039 readers
643 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] rektdeckard 12 points 2 weeks ago (4 children)

It's a handy way to convert any value to a Boolean. If window.chrome is defined and done non-empty value, double negation turns it into just true.

[–] [email protected] 6 points 2 weeks ago (3 children)

I've been wondering why not window.chrome == true or Boolean(window.chrome), but it turns out that the former doesn't work and that == has essentially no use unless you remember some completely arbitrary rules, and that JS developers would complain that the latter is too long given the fact that I've seen javascript code using !0 for true and !1 for false, instead of just true and false because they can save 2 to 3 characters that way.

[–] [email protected] 5 points 1 week ago (1 children)

I've never seen the !0 and !1, it is dumb and indicates either young or terrible devs.

Boolean(window.chrome) is the best, !!window.chrome is good, no need to test if it's equal to true if you make it a boolean beforehand.

[–] RedStrider 1 points 1 week ago

i just added the === true for clarity

load more comments (1 replies)
load more comments (1 replies)