DEV Community

Discussion on: You don't need null

Collapse
 
leob profile image
leob • Edited

No ... you're saying "folks that use it a lot ... get pretty mad" - I'm not mad at you lol ... but I still see value in explicitly assigning null, and undefined is a distinct case.

The point is that "undefined" is automatically there, while what I want is for programmers to explicitly and deliberately initialize their variables - be it to null, or zero, or an empty string, or whatever makes sense. But explicitly initializing a variable to "undefined" makes no sense (because by definition it already has that value).

If you really want to get rid of null pointers and of "having to check for null everywhere" then you should introduce an "optional" concept (like Rust has, or even Typescript).

Collapse
 
loucyx profile image
Lou Cyx

We have "optional" with JS, you just use default values (only works if the passed value is undefined), nullish coalescing and optional chaining (this last two work withnull as well). TS after all is just a superset of JS, the types it uses are just the explicit version of JS types (also seen in JSDocs).

Thanks for not getting mad. Trust me, there are some folks here pretty vocal about their opinions not matching with mine 😅

Collapse
 
leob profile image
leob

People should remain rational, getting all emotional over tech debates is a bit stupid lol

Some comments have been hidden by the post's author - find out more