This differs from undefined which is to say that the value does not exist because it was unset. Why would we spend memory with a null value there, or bits with a JSON coming from the back-end, when we can just omit what is not there? If you work in the field, how long have you been at it? Like comment: Like comment: 4 likesĮnter fullscreen mode Exit fullscreen mode It’s got an entirely different purpose than null. Undefined is metadata that describes a js value that’s integral to its duck typing system. This problem exists because there’s only one null. The system has now made an incorrect assumption because of a limitation between being able to discern whether the data should be there but wasn’t or whether it was there and was intended to be null. After all, they default to null if the field is not present in the json payload. You have forgotten to send over this middle name field because of how js’s type system works, and because of how the deserializers work, they do not know whether to reject the request or not. That third party system is written in a strongly typed language (Java or C#). Now you want to integrate with a third party web api. They may choose to acknowledge that they have no middle name, at which point you’d save null to the document. You could prompt those that have not yet taken an action because you can clearly see that the field is missing/undefined. You decide that, in order to facilitate data collection, you want to prompt any existing users that are missing this field. Null is still valid, because not everyone has a middle name. Later, you decide to include a middle name. You started by only collecting first and last name, and have thousands of documents that are missing this field. Taking this further, let’s say your data store is Mongo. Null differs, if you’re using it correctly. Undefined means no deliberate choice has been applied to it. Perhaps the form to enter the person details was only partially completed. This is to say that the actual value is deliberately meant to be no middle name. If they do not have a middle name, it would be null. Undefined means it does not exist because it’s unset and was never set.ĭoes a person have a middle name? If yes, it will have an alpha value. Null is a valid value to represent anything that is nullable in nature.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |