- Feature Articles
- CodeSOD
- Error'd
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
What if it's not mobile, but is android and iPhone at the same time?
Admin
Or just plain don't send the whole if() branch of the JS (or send the if() branch without the if(){} around it in the opposite case). Sheesh.
Admin
Or, worse, what if it's mobile, android, iPhone and iPad all at once (where "mobile" means "Windows Mobile", of course...).
Admin
How do you justify calling it "abuse"? I do that frequently. It is correctly using the order . . . what's wrong with that?
Admin
I'm not a JavaScript expert, but can it be that "true" === "true" evaluates to false because these two strings are equal but not identical?
Admin
That would be a pretty severe violation of POLA if
"true" == "true"
and"true" === "true"
weren't bothtrue
.(For the folks who don't know about POLA: "Principle of Least Astonishment".)
Admin
JavaScript has plenty of POLA violations, but I don't think that is one.
Admin
Indeed, it isn't, as revealed by the JS console in Firefox. with == and with ===, the result is the same.
Admin
They're probably not
true
, but are"true"
.Admin
No, they (er, the results of the comparisons) really are (according to the console in Firefox) the booleans rather than strings.
Admin
In JS strings are primitives, meaning their equality logic doesn't follow the same logic as comparing objects(where any two objects are different even with the same contents).
=== really just means it passes the same check as == AND they're the same type.
"1" == 1
is true, but"1" === 1
is false because their type is different.The weird exception to this is the Symbol primitive, which acts like an object in that they're all different on comparisons unless they're the exact same Symbol, even using ==.
Symbol("foo") == Symbol("foo")
is false.Admin
That reminded me of the old joke, "In Heaven, the Germans are the engineers, the French are the cooks and the English are the policemen."
In Heaven, the security is done by iPhone, screen size is by iPad, open source is by Android. I've never used a WinMobile device so I don't know what their strong suits were hahaha
Admin
It doesn't matter what the precedence of
=
is because this code doesn't use the assignment operator; it uses initialization, which is syntactically distinct from expressions. (Try(var x = 0)
orvar (x = 0)
: You'll get a syntax error.)Admin
= in a var statement isn't an operator. It's initializer syntax. Precedence doesn't apply.
While you should rely on capability detection and styling rather than user agent sniffing, projects in the real world (especially those that use var) have to deal with browser quirks and odd requirements, or used to.
Admin
Especially if you've ever done something like browser game development targeted at mobile, the usual rules on capability sniffing generally start falling down, as there are things you need to check that are not covered by capability sniffing.
For example: iOS at some point disabled the capability of going to fullscreen programatically (or at least did at a certain iOS version, and IIRC, it was maybe removed only on phone, but not tablet). Whilst you can detect that programatically (by knowing that you got a runtime exception when trying to invoke that api), the common solution adopted in the world of mobile gambling, is to allow a "swipe for full screen" gesture. If you want that implemented only on iOS, you need to start knowing about your environment you're running in. (Note that this all might have changed since I was doing this - the general rule on mobile, is nothing stays the same for long).
It's not a pretty solution, for sure, but I don't fully agree with "you should always be using capability detection", because sometimes, there just isn't an obvious way to do that (and you can be aware that all of your rival game developers sure arent using capability detection to solve the same problem either)
Admin
Laying tiles, of course.
Admin
I'm sorry, but don't understand what the problem is here.
===
compares two things and=
is assignment. Even ignoring the fact that these are all initialisers in the example, assigning the result of an equality comparison to a (boolean) variable is hardly a WTF and if anybody finds it difficult to make sense of, I suggest they do not seek to make a career in computer programming.Admin
TRWTF is split processing server/client. The bane of computing history.
Admin
They are identical since both are representations of the same string in the string pool
Admin
I'm sorry, can someone explain for n00bs like me how
if (false === true)
isn't always a no-op, and howvar isMobile = "" === "true"
etc. is not the same asvar isMobile = false
?