I have a case where I have a dictionary object and a value with no key.
The object can have the system values and then a user value. I have to store that value.
I could use a reserved word or I could use null.
userValue = "enabled"; data = {version: 10, date: 10101010}; data.name = "Charleen"; // reserved word data["MyReservedWordIHopeNoOneStumblesUpon"] = userValue; // or use null data[null] = userValues; If I use a reserved word a user may stumble upon it one day (highly unlikely). That reserved word would also be stored or saved and may not make sense.
I could also use null or undefined as keys. But if I was iterating through the object and I encountered null or undefined they could be bugs that I dismissed as coming from user values.
The code is not that complicated in that I could easily debug it and I could check for reserved words or null.
Have you ever used null or undefined as keys and is there any pros or cons or recommendations to doing so?
Note: Typescript gives a warning:
Type 'null' cannot be used as an index
But it works in ES6.