I am never going to complain about Python again

MRAB python at mrabarnett.plus.com
Thu Oct 10 07:10:40 EDT 2013


On 10/10/2013 09:23, Frank Millman wrote:
>
> "Steven D'Aprano" <steve at pearwood.info> wrote in message
> news:52562ee3$0$2931$c3e8da3$76491128 at news.astraweb.com...
>> Just came across this little Javascript gem:
>>
>> ",,," == Array((null,'cool',false,NaN,4));
>>
>> => evaluates as true
>>
>> http://wtfjs.com/2011/02/11/all-your-commas-are-belong-to-Array
>>
>> I swear, I am never going to complain about Python again.
>>
>
> I am sure you know this, but for the record, Javascript has two equality
> operators, '==' and '==='.
>
> The double form attempts to coerce the left and right sides to the same
> type, the triple form does not.
>
Re "==", this page:

     http://php.net/manual/en/language.operators.comparison.php

states:

"""If you compare a number with a string or the *comparison involves
numerical strings*, then each string is converted to a number and the
comparison performed numerically.""" (emphasis added)

So they get coerced to numbers if they _look_ like numbers!

> '1' == 1 returns true
>
> '1' === 1 returns false
>
> The moment I discovered this, I changed all my operators from the double
> form to the triple form. Now I no longer have surprises of this nature.
>




More information about the Python-list mailing list