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.