On the server, I serialize my objects and sometimes, some properties are null. On the page, when I parse the string, the null properties are deserialized correctly and in my javascript, I test to see if the properties for which there might be a null are indeed null or not before working with them; like this:
if (TheObject.TheProp && TheObject.TheProp.length) {...}
It doesn’t crash and it works. My question is this: should I, on the server, populate every property with something (ie. “” for strings and 0 for numbers) because it’s considered good practice or is it ok to have null properties on the page?
Thanks for your suggestions.
In JavaScript
nullis a value just like""and0. A value isundefinedif you have defined it, but not assigned a value, but even that is fine.undefinedwill never occur in a JSON data structure though.Just make sure you handle the
nulls correctly and you should be fine.