mireero wrote:
^^^^^^^
Your real name belongs in your From header field value if you desire
more/further answers.
> Is there any good reason for using "===" instead of "==" (apart from a
> slight improve in performance, I once read a 4% faster for "===") ?
Yes.
> If I have:
> typeof some_var;
> This will always returns(*) a string like in:
> console.log(typeof document);
> => "object"
>
> If I do the comparison of typeof some_var against a string, there
> shouldn't be any casting.
Correct.
> When someone wants to test if some variable is defined, I usually see:
> if (typeof some_var === "undefined") {
> Would I have the expected and identical behavior with:
> if (typeof some_var == "undefined") {
Yes, except that your code linter might give you a confusing warning.
> I can't see why it wouldn't but as I keep reading "===", I thought I'd
> better ask!
AFAIK, the code linter that considers the type of expressions when checking
the use of equals operators is yet to be written.
> (*)
> typeof is an operator, not a function.
Correct. Therefore you have correctly _not_ written it like a function call
even though the grammar would allow that.
> Semantically, is it correct to say that typeof "returns" something ?
I do not think so, although the issue becomes more complicated with operator
overloading (that, AFAIK, ECMAScript [ES] implementations so far only
support implicitly with the .toString() and .valueOf() methods). Therefore,
in order to avoid misconceptions, when talking about operators in ES
implementations, I use the verbs “(to) yield” and “(to) result (in)”
instead.
--
PointedEars
FAQ: <
http://PointedEars.de/faq> | SVN: <
http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <
http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.