Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript reserved words

Tags:

javascript

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

like image 237
user1032531 Avatar asked Mar 26 '26 07:03

user1032531


1 Answers

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.

like image 50
Jamie Dixon Avatar answered Mar 27 '26 19:03

Jamie Dixon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!