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

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

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

Garrett Smith

On Tue, May 27, 2008 at 3:38 PM, Jonas Sicking <[hidden email]> 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

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