typeof null, and criticism of idiots who wrote isNull

# Garrett Smith (17 years ago)

Something I read on the wiki.

proposals:typeof

Douglas Crockford: | I think it is too late to fix typeof. The change proposed for | typeof null will break existing code. For example, isNull | functions have been written by idiots as | | function isNull(a) { | return typeof a == 'object' && !a; | } | | It is possible to write an isNull that performs correctly with | the fixed typeof, but existing code cannot anticipate the change. | | Perhaps a better alternative is a new operator, maybe called | typeString, which works the way typeof should work, including | | typeString [] === 'array' | | (Hi Doug – please sign your comments. Use the feather-icon button at | the right end of the in-page toolbar. Thanks!) `---------------------------------------------------------------

It does seem poor choice, as the anonymous post indicates, to use an isNull function. x === null, inline, is clearer, is much faster, and doesn't introduce an unneeded dependency. It seems that the post calling the authors of this code "idiots" is apparently the author himself. Yeah? Maybe it's a joke?

groups.google.com/group/comp.lang.javascript/msg/30ea9f75ccc87524?dmode=source

Douglas Crockford: | Yup. I put stuff like that into so functions. For example, | | function isFunction(a) { | return typeof a == 'function'; | } | function isNull(a) { | return typeof a == 'object' && !a; | } `---------------------------------------------------------------

Oh well. Most of us write dumb stuff once in a while. I just thought it was odd: Saying such code "has been written by idiots" was apparently written by the very same person.

I can't find real world code using such isNull code -- that c.l.javascript post is the only place I found it (though I didn't search that hard).

Garrett

# Peter Michaux (17 years ago)

From the ECMAScript wiki:

| I think it is too late to fix typeof. The change proposed for | typeof null will break existing code. For example, isNull | functions have been written by idiots as

I hope, given the new aspiration of "harmony", this sort of language, which amounts to name calling, is phased out as it only serves to alienate. Though different word choice, it is quite easily possible to avoid both name calling and mincing words.

Peter