Can I use an empty string as an object identifier?

Yes, technically its totally valid and you can safely use it. An object key needs to be a “string”, which does not exclude an empty string.

If that is convenient or even useful is another story.

See Should I use an empty property key?


Since the ’empty string’ is one of the falsy values in ecmascript, consider the following example:

var foo = {
    ':-)': 'face',
    'answer': 42,
    '': 'empty'
};

Object.keys( foo ).forEach(function( key ) {
    if( key ) {
        console.log(key);
    }
});

That snippet would only log :-) and answer. So that is one pitfall for doing this.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)