In this matter again I agree 100% with Crockford: it's the ==
automatic type casting/coercing what's most of the times a useless
risk.
You have your viewpoint (I think/hope it's really but not just forced by
authority), nobody can prevent you of using typeof foo === "string".
But what's the most funny, once people have knew that there is no
difference, after that their hands won't up to write === in such case as
with `typeof` and they write ==. Why? I think, just a human logic --
they see a big contradiction: on one hand -- "authority said" and showed
me some scary synthetic primitive examples with losing transitivity and
some very scary examples with falsy values (which are all == to `false`
-- yeah, in dynamic language). On the other hand they really can't
understand for what any reason they should continue to write === with
`typeof` comparing its result with another string.
You loose nothing by typing typeof x === "sometype" (it's not
even true as you say that it counts as one more char, not when
gzipped)
Yes, the example with losing one "byte" is also very synthetic and
showed just for "fun" (?). On practice of course nobody will think about
"few bytes". As I mentioned myself -- a normal functioning of the system
is much essential than that.
but you have wasted your time in writing a long-winded page
to defend an hypothetical, dubious advantage in avoiding a strict
comparison where a non strict one would do.
No, no way -- that wasn't the goal of that note. The goal was/is to show
that there are /completely/ safe-cases which are /specified/ by the
standard, and which means that /nothing/ can go wrong. And also the goal
to show algorithms of == and ===, and to show they are equal in such
cases. And I'm telling you, after people find out it, they first have
some "systemic contradiction" (for a while) and after that start to
write == with `typeof`. Because when they write a code and reach the
line with `typeof` they /can't/ anymore write === because /understand/
and /know/ that they are safe in this case.
I do not force anyone to write so. Moreover as I said, I think that a
programmer need not remember much about some == to avoid ambiguities.
That all languages should go that way -- increasing of an abstraction to
be able easy understand and remember the language's constructions.
Additionally, I also recommend using === in many cases (including cases
with booleans) and I assume that a programmer can even forgot what
results `typeof` (yeah, really, maybe it results a number? or an object?
and I need a string on the right hand side -- so I use ===), and I
conclude that it isn't a crime to use === everywhere.
I just show the /completely/ safe-cases and that algorithms are equal in
some cases. That's it. No more, no less.
Personally, I use === when is needed, and == in all other cases.
Additionally, if I forgot some case, I use always ===. That's my rules.
And it's convenient for me. You have other rules, which more convenient
for you.
I wonder why so many
people keep wasting so much time and effort with the sole purpose of
pretending to be more clever than Crockford.
Yeah, funny demagogy
Don't worry, I have immunity for it.
He is him, you just be
yourself.
Yes, who said different? I am me. I have a name and my thoughts. You
(and any authority you believe) have yours. We can exchange our meanings.
Dmitry.