re: Unhealthy Code: Null Checks Everywhere! VIEW POST

TOP OF THREAD FULL DISCUSSION
re: What about using undefined instead of null? Better or worse?
 

Undefined in javascript is what null is in other languages. I think its better to use it. Best is to avoid both.

But a lot of js developers expect a null. A lot of libs return null (some even return either, with no reason for one or the other). And js itself also returns null, for example getElementById.

 

The reason I use it is that if you see a null you known that it was explicitly set, where as undefined means it hasn't been touched.

Would you recommend just sticking to undefined rather than mixing null and undefined?

code of conduct - report abuse