Search code examples
javascriptparametersquotes

Single Quote Params vs No Quote Params?


This is something that's been mind boggling to me for a while, some times I see people writing javascript objects like so with single quote params:

{
    'name': 'Teddy',
    'last': 'Monster'
}

But then I also see the more common, no quote params:

{
    name: 'Teddy',
    last: 'Monster'
}

Is there a reason one would use single quote params? Is it faster to parse?

From what I can see, there is no speed difference, rather just cluttering the file with unnecessary quotes and increasing file size.

I'll change my mind if I can get a straight answer :)


Solution

  • You can't define this hash:

    {
       function: 'foo'
    }
    

    But you can define

    {
       'function': 'foo'
    }
    

    Personally, I use the former way, if there's no reserved keywords as keys (as to not clutter the code, like you've pointed out).