0 == false == ""

T

Tim Streater

(e-mail address removed) (Arnaud Diederen
(aundro)) said:
That's very PointedEars of you, Thomas (I know it doesn't actually
mean anything, but those who have read your prose will probably
understand it anyway).


It's not so much a matter of "what's true and what's false" (*) as
it a matter of " *how do you get* to those values", and that...

Try writing "true" or "false" as required.
 
T

Thomas 'PointedEars' Lahn

Tim said:
Anyone doing a type conversion of string to boolean needs a good smack.

Anyone making such a statement has no clue what they are talking about.

Besides, all generalizations are false ;-)


PointedEars
 
T

Tim Streater

Thomas 'PointedEars' Lahn said:
Anyone making such a statement has no clue what they are talking about.

Besides, all generalizations are false ;-)

You mean - the string I typed in evaluates to "false" ??

Damn.
 
D

Douglas Crockford

You should use it only when it is needed.

Too often I see things like this:

typeof o === 'object'

This makes no sense as a typeof operation evaluates to a string
(comparing two strings doesn't involve implicit type conversion.)

However, for example, if a function's argument x can be a string or
null, then strict comparison would be the way to test it:

x === null

If you used a loose comparison on an empty string, you would get the
wrong result.

I think you should use the operator that always gives the right result,
and never use the operator that sometimes gives the wrong result.

http://javascript.crockford.com/
 
D

David Mark

I think you should use the operator that always gives the right result,
and never use the operator that sometimes gives the wrong result.

For the first example, the == operator will always give the right
result. For the second it will not. I don't see any benefit in using
the === operator for everything. To me it makes the code's intentions
less clear.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,600
Members
45,180
Latest member
CryptoTax Software
Top