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

Programmer Humor

32404 readers
1217 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 3 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] BroBot9000@lemmy.world 16 points 2 years ago (3 children)

I’m going to have to go down the rabbit hole of making my own website soon. Just curious but would there be an easy way to show a pop up just to people using chrome?

No reason in particular… 😏

[–] RedStrider@lemmy.world 18 points 2 years ago (1 children)

lol i did something like what i assume your goal is on my neocities when i detect !!window.chrome === true

[–] Faresh@lemmy.ml 7 points 2 years ago (2 children)
[–] rektdeckard@lemmy.world 12 points 2 years ago (1 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.

[–] Faresh@lemmy.ml 6 points 2 years ago (2 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.

[–] marcos@lemmy.world 6 points 2 years ago

== has essentially no use unless you remember some completely arbitrary rules

If you make sure the types match, like by explicitly converting things on the same line on that example, then you can use it just like if it was ===.

In fact, there are people that defend that if your code behaves differently when you switch those two operators, your code is wrong. (Personally, I defend that JS it a pile of dogshit, and you should avoid going to dig there.)

[–] ivn@jlai.lu 5 points 2 years 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@lemmy.world 1 points 1 year ago

i just added the === true for clarity

[–] CorvidCawder@sh.itjust.works 5 points 2 years ago

JS "idiomatic" way to cast to boolean. But could just be written as !window.chrome instead.

[–] Supervisor194@lemmy.world 15 points 2 years ago

Not sure if serious, but there's a million ways to do this, some that require importing thousands of lines of code and none of which are guaranteed to work in all possible circumstances. But here's a simple one.

[–] gamermanh@lemmy.dbzer0.com 6 points 2 years ago (1 children)

Im stupid Stones but I think it's in the user agent information, browser and version and other shit

[–] ClassifiedPancake@discuss.tchncs.de 6 points 2 years ago (1 children)

User agents cannot be fully trusted anymore since every browser puts every possible word in it so they are not excluded by anything.

[–] umbraroze@lemmy.world 1 points 2 years ago

Well, some browsers have made User-Agent strings useless. Technically, it's like this:

Firefox: "Mozilla based browser, Gecko engine, Firefox."

Chromium: "We're totally a Mozilla based browser we swear. Also KHTML, which is like Gecko basically. I guess also a bit like WebKit. Has anyone ever heard of those? No? OK. Fine, here's some actual information then..."