Javascript reserved words

I created an object that worked fine with FF, but led to an error with IE (expected identifier, string or number)

var a={text:'abc',class:'def'};

After researching the litter, I found the class a reserved word. Quoting the word “class” fixed the problem.

var a={text:'abc',"class":'def'};

Is it always recommended that you provide an object name to resolve these errors?

thank

+3
source share
2 answers

No, this is not recommended.

We recommend simply not to use reserved words like this. You can easily change classto anything else.

+4
source

All Articles