Tuesday, September 18, 2007

0=="" is true

Debugging something on Sahi, came across this interesting equality in javascript:

0 == "" is true!

So are:

1 == "1" etc.

An easy way to test these out (and any other single line javascript) is to type

javascript:0==""

on the browser url navigation bar.
Yes, it works on IE and firefox.

3 comments:

Anonymous said...

An untyped / interpreted language issue?

Palani Murugan N said...

"enna kodumai saravana ithu" :D

Anonymous said...

No, a not knowing javascript issue. The equality operator in javascript is ===, not ==. See douglas crockford's (yahoo javascript guru) website: http://www.jslint.com/lint.html down the page there is a header == and !=.
Also see http://www.jslint.com