undefined != null ?

Sep 7, 2010 at 3:37 PM

Hi.

While I was trying to run this script:

function foo(parameter){
var out;
if (parameter != null)
    out = parameter;
else
    out = 0;
return out;
}

var bar = foo();

I saw that it returns undefined, so I understood that null and undefined are different for Jint.

I don't know if this is the right place to ask this question, but I tried this same script on Spidermonkey (firefox with firebug) and I noticed that it gets "undefined" (calling "foo" with no parameters means calling foo(undefined), isn't it?) but when it compares undefined with null, it behaves like they are the same thing, thus going to "out = 0" and returning 0.

Does anybody have an explanation of this behaviour? (I know, I should ask to spidermonkey's men... but unfortunately my boss keeps SM as a "de facto" standard, so I'd better know if I have to customize also this Jint behaviour, like it happened on implied globals...)

Thank you again for your patience

Coordinator
Sep 7, 2010 at 5:47 PM

I don't know what should be the real behavior, I will investigate, though in the meantime I would change your script to

if (parameter)
    out = parameter;

Which will handle both cases

Coordinator
Sep 7, 2010 at 6:29 PM

I have corrected it, this was a bug. It's on mercurial.

Sep 8, 2010 at 7:28 AM

wow, faster than light!

Yesterday I saw that actually you can say that undefined == null is true and undefined === null is false.

Thank you very much again