On Tue, May 27, 2008 at 3:38 PM, Jonas Sicking <
jonas@...> 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