Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6887397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:52:48+00:00 2026-05-27T05:52:48+00:00

I’ve tested this only in Firefox, but apparently you can use an empty string

  • 0

I’ve tested this only in Firefox, but apparently you can use an empty string as a key to a property in an 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
}

In skimming through the EcmaScript specs, it appears that (at least in 5), property keys are defined as strings, and strings as 0 or more characters. This implies that an empty string is a valid property name according to the specs.

Anyway, I’m tempted to use this in a section of code where I’m calculating summaries of some counts by the status of a data item (similar to what I’ve shown above). There are some items which might not have a status, and I need a placeholder for those. Since statuses are user-definable, I don’t want to risk using a dummy word that might conflict.

It seems so simple and elegant, in looking at the data I can easily tell what the blank string would mean. It also makes the code a little bit more efficient, since the empty string would be the exact value of the status in the items without a status.

But at the same time, my instincts are telling me that something is wrong with it. I mean, apart from the chance that some browser might not support this, I feel like I’ve encountered a bug in JavaScript that will be fixed some day. But, at the same time, that’s the same feeling I once had about a lot of other JavaScript features that I now use every day (such as the time I discovered that && and || returns the value of one of the operands, not just true or false).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:52:48+00:00Added an answer on May 27, 2026 at 5:52 am

    An object’s key must be a string, and the empty string ('') is a string. There is no cross browser issue that I’ve ever come across with empty strings, although there have been very few occasions where I thought it was acceptable to use an empty string as a key name.

    I would discourage the general usage of '' as a key, but for a simple lookup, it’ll work just fine, and sounds reasonable. It’s a good place to add a comment noting the exceptional circumstance.

    Additionally, during lookup you may have issues with values that are cast to a string:

    o = {...} //some object
    foo = 'bar';
    
    //some examples
    o[foo] //will return o['bar']
    o[null] //will return o['null']
    o[undefined] //will return o['undefined']
    

    If you’d like to have null and undefined use the '' key, you may need to use a fallback:

    key = key || '';
    

    If you might have non-string values passed in, it’s important to cast too:

    key = key || '';
    key = '' + key;
    

    note that a value of 0 will turn into '', whereas a value of '0' will stay '0'.


    In most cases, I find I’m picking a pre-defined value out of a hashtable object. To check that the value exists on the object there are a number of options:

    //will be falsey if the value is falsey
    if (o[key]) {...}
    
    //will return true for properties on the object as well as in the prototype hierarchy
    if (key in o) {...}
    
    //returns true only for properties on the object instance
    if (o.hasOwnProperty(key)) {...}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
i got an object with contents of html markup in it, for example: string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.