I tested this only in Firefox, but apparently you can use the empty string as the key to the property in the object. For example, see the first property here:
var countsByStatus = { "": 23, //unknown status "started": 45, "draft": 3, "accepted": 23, "hold": 2345, "fixed": 2, "published": 345 }
When viewing EcmaScript specifications, it appears (at least in 5), property keys are defined as strings, and strings are 0 or more characters. This means that the empty string is a valid property name according to the specifications.
In any case, I am tempted to use this in the code section, where I calculate a summary of some values ββby the status of the data item (similar to what I showed above). There are some elements that may not have status, and I need a placeholder for them. Since statuses are user-defined, I donβt want to risk using a dummy word that could conflict.
It seems so simple and elegant, looking at the data, I can easily say what an empty string would mean. It also makes the code a bit more efficient, since an empty string will be the exact status value in elements with no status.
But at the same time, my instincts tell me that something is wrong with this. I mean, in addition to the fact that some browsers may not support this, I feel that I have encountered a bug in JavaScript that will be fixed once. But at the same time, it feels like I once had many other JavaScript functions that I use every day now (for example, when I found that && and || returns the value of one of the operands, and not just true or false).
javascript
user4815162342 Dec 01 '11 at 15:34 2011-12-01 15:34
source share