I'm curious why in javascript the following code is returning an error:
null.toString()
where in other languages such as ruby, it renders the "logical" empty string:
nil.to_s # ""
I was curious about the behaviour since:
typeof null == "object"
So I thought it would make sense to have the prototype toString() "attached" to it. It seems typeof null
returns object
only for legacy reasons: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null