Reputation: 26281
I made an object which worked fine with FF but resulted in an error with IE (expected identifier, string or number)
var a={text:'abc',class:'def'};
After a litter research, I found class is a reserved word. Quoting the word "class" fixed the problem.
var a={text:'abc',"class":'def'};
Is it recommended to always quote the object name to eliminate these errors?
Thanks
Upvotes: 3
Views: 358
Reputation: 235982
Just have a look here:
https://developer.mozilla.org/en/JavaScript/Reference/Reserved_Words
and don't use any of those words unquoted within object literals.
Upvotes: 4
Reputation: 53991
No it's not something that is generally recommended.
What IS recommended is to simply not used reserved words like this. You can quite easily change class
to be anything else.
Upvotes: 4