DEV Community

Discussion on: The Difference Between Null and Undefined in JavaScript

 
analog_heart profile image
BP

I cannot effectively respond as I’m in my phone.

If you filled a form partially, you can just use undefined.

Yes, it would be undefined by default. That’s my point.

Both mean "nullish/empty/missing value", making the distinction between intentionally left empty or not makes no sense.

They do not because one requires an action to be applied. Intent rather than an assumption. Null does not mean a missing value in the way you are describing. That is expressly the purpose of undefined in js.

You're basically describing a poorly designed API/back-end. If you have a back-end that doesn't have the concept of an optional/undefined property, then you should acomodate for that. Front-end shouldn't be fixing issues of the back-end (which is a pretty common mistake).

First - and my main point - is to point out the flaw in those languages that happens to not exist in js because js actually got something right. But secondly, do you often have control over the third party systems you integrate with? 🤔

If the middleName field becomes required, then you could say that if it isn't a string, then it wasn't filled yet (undefined), and if is intentionally left empty, then is just an empty string "", again no need for null here.

Apply this to an integer. Do you fallback to zero as default? You’re being too narrow in your reading.

I'm not the only one that says this, if you don't want to take my word for it, maybe you'll take the word of Douglas Crockford (the author of "JavaScript: The Good Parts" and JSON) here.

I’m aware of him, and he is not infallible. This is an example.

I don't know how is my time in this field relevant, but if you really want to know, I been doing this for 10+ years

It’s relevant because you keep citing “real world examples”, yet are advocating for lossy handling of data. It makes no sense and does not fit well with practical experience, imo.