different results on a logical

T

transkawa

why do i get different results for this two logical connectives:
1. while( !filterGuess(guess,y)) //i.e when false
2. while( filterGuess(guess,y) == 'false')
as for 2, i got the wrong result. i tried type equality checking, ===,
and still got the same wrong result for 2.
please, can someone help me explain why i got wrong result for 2 but 1
returned the right response?
the filter function is:
function filterGuess(guess,y){
return (!(Math.abs(guess - y) > 0.00001)); //returns true if within
tolerance
}
TIA.
xnt
 
E

Evertjan.

transkawa wrote on 08 jun 2010 in comp.lang.javascript:
2 filterGuess(guess,y) == 'false'

if ( boolenaValue == 'false' )

'false' is a non-empty string so wil be seen as a boolean true.
as for 2, i got the wrong result. i tried type equality checking, ===,
and still got the same wrong result for 2.

if ( boolenaValue === 'false' )

a boolean is never exactly a string

==============

Better read the Javascript specs and NG FAQ first.
 

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
474,269
Messages
2,571,100
Members
48,773
Latest member
Kaybee

Latest Threads

Top