Coding since 11yo, that makes it over 30 years now ~~~
Have a PhD in Comp Sci ~~~
Love to go on bike tours ~~~
I try to stay as generalist as I can in this crazy wide place coding is at now.
I teach college web development classes in Denmark and I have been messing around on the Internet since the WWW became a thing.
I love simple solutions and humour!
Coding since 11yo, that makes it over 30 years now ~~~
Have a PhD in Comp Sci ~~~
Love to go on bike tours ~~~
I try to stay as generalist as I can in this crazy wide place coding is at now.
In JS there are very few object-type calls that work in any way with nulls, so it's neat that they aimed to make this aspect of the language more OO, but they should have followed through better. typeof(null) being 'object' is seldom anything but annoying for JS devs.
Absolutely true. I was only referring to the use of the word "insane" which just sounds very unknowing/ignorant to me.
FWIW, now that we use TS for most things, this is not problem for us often, except for when something is nullable ánd multiple types (object/number/string/undefined).
My recommendation is to never use null and only use undefined. Replace your "null"s with an "EMPTY/UN_SET" data type.
Coding since 11yo, that makes it over 30 years now ~~~
Have a PhD in Comp Sci ~~~
Love to go on bike tours ~~~
I try to stay as generalist as I can in this crazy wide place coding is at now.
Fair enough. I didn't mean insane in the sense of completely without reason, just in the sense that it was badly thought out.
The thing is that nulls are now baked into JS at a few levels, so in our own code we can avoid them, but they pop up throughout the various JS apis, eg
That's what I mean by the loose "insane" comment. It was a mistake that was bad enough that as JS devs we're now best off to generally avoid the fundamental null value in JS.
I totally agree with you about TS, which corrects many of these issues, and how in JS we're best to use undefined whereever possible.
This took an hour of my life:
yep, a good check for an actual object is
Kind of insane they did that that.
Or
Object.prototype.toString.call(thing)
It's not insane.
null
, likenil
in ruby, a singleton instance of NilClass is technically an object.Technically an array is also an object, which is why there is Array.isArray (which has its own caveats).
But at least ruby is rigorously consistent OO like that.
In JS there are very few object-type calls that work in any way with nulls, so it's neat that they aimed to make this aspect of the language more OO, but they should have followed through better.
typeof(null)
being 'object' is seldom anything but annoying for JS devs.eg.
Basically there are very few times you might write
typeof(thing)==='object'
where you shouldn't do the null check tooAbsolutely true. I was only referring to the use of the word "insane" which just sounds very unknowing/ignorant to me.
FWIW, now that we use TS for most things, this is not problem for us often, except for when something is nullable ánd multiple types (object/number/string/undefined).
My recommendation is to never use
null
and only useundefined
. Replace your "null"s with an "EMPTY/UN_SET" data type.Fair enough. I didn't mean insane in the sense of completely without reason, just in the sense that it was badly thought out.
The thing is that nulls are now baked into JS at a few levels, so in our own code we can avoid them, but they pop up throughout the various JS apis, eg
That's what I mean by the loose "insane" comment. It was a mistake that was bad enough that as JS devs we're now best off to generally avoid the fundamental null value in JS.
I totally agree with you about TS, which corrects many of these issues, and how in JS we're best to use
undefined
whereever possible.omg thank you for your service as I really didn’t know about this.