Re: [WebIDL] ToString( Null ) => "null" :: Ecma-262 r3

On Tue, May 27, 2008 at 3:38 PM, Jonas Sicking <jonas@sicking.cc> wrote:
>

Hey Jonas,

> Granted, this is partially due to a javascript spec "bug", null really
> should have serialized to "" rather than "null".
>

The value null, when passed to ToString, converts to the string
literal "null". I don't agree that that's a bug. This is how the
language was designed and I think it was a right choice. Other
programming languages use this approach, too. I think it is intuitive
because:

var el = document.getElementById( arg );
console.log( el );

- will print "null" to the console, if arg is not found (resulting in
el being null). This is useful.

It is very simple, when desired, to do:-

if(s === null) s = "";

It would seem wrong for null to convert to the string "" when passed
to ToString.

I don't suppose you'd rather have ToString( Undefined ) to result in
"undefined"?

Garrett

Received on Tuesday, 27 May 2008 23:29:53 UTC