Kanye treats Bianca like a lab rat. This is nauseating coercive control - carried out in front of the whole world, says LAURA CRAIK
Love Island's Ekin-Su's WILD heart rate challenge routine divides viewers as she leaves her 'uncomfortable' co-stars stunned
The Essex Sainsbury’s that locals say is the ‘worst maintained in Britain’ and has 'very tricky' car park
Family pays tribute to 'extraordinary young man' who died in Colchester crash
How Prince Philip was Queen Elizabeth's 'ideas man' - from creating The Duke of Edinburgh Award to pivotal decision at Princess Diana's funeral
Can you guess who these eye-catching handbags belong to? Match the arm candy to the royal...
Pitsea crash: Charity's tribute after death of brother, 16, and sister, 9, in tragic crash
Elon Musk gets powerful new ally who vows to destroy anyone who sabotages DOGE's DC shakeup
Beyonce slammed by country legend over Grammy win amid DEI push to make awards more diverse
Teddi Mellencamp finally breaks her silence on the affair that ended her marriage: 'There was somebody else'
CodeSOD: Device Detection
There are a lot of cases where the submission is "this was server side generated JavaScript and they were loading constants". Which, honestly, is a WTF, but it isn't interesting code. Things like this:
if (false === true) { // do stuff }That's absolutely the wrong way to do that, and I hate it, but there's just so many times you can say, "send server-side values to the client as an object, not inline".
But Daniel's electrical provider decided to come up with an example of this that really takes it to the next level of grossness.
var isMobile = "" === "true"; var isAndroid = "" === "true"; var isIPad = "" === "true"; var isIPhone = "" === "true";For starters, they're doing device detection on the server side, which isn't the worst possible idea, but it means they're relying on header fields or worse: the user agent string. Maybe they're checking the device resolution. The fact that they're naming specific devices instead of browser capabilities hints at a terrible hackjob of reactive webdesign- likely someone wrote a bunch of JavaScript that alters the desktop stylesheet to cram the desktop site onto a mobile device. But that's just background noise.
Look at that code.
First, we've got some lovely order-of-operations abuse: === has higher precedence than =, which makes sense but hardly makes this code readable. The first time I saw this, my brain wanted the assignment to happen first.
But what's really special to me is the insistence on making this stringly typed. They control both sides of the code, so they could have just done booleans on both sides. And sure, there's a world where they're just dumb, or didn't trust their templating engine to handle that well.
I've seen enough bad code, though, to have a different suspicion. I can't confirm it, but c'mon, you know in your hearts this is true: the function which is doing device detection returns a string itself, and that string isn't always a boolean for some reason. So they needed to wrap the output in quotes, because that was the only way to make sure that the JavaScript actually could be executed without a syntax error.
I can't be sure that's true from this little snippet. But look at this code, and tell me that someone didn't make that mistake.
.comment { border: none; }