Unquoted property names / object keys in JavaScript

Fun fact: var foo = { H̹̙̦̮͉̩̗̗ͧ̇̏̊̾Eͨ͆͒̆ͮ̃͏̷̮̣̫̤̣Cͯ̂͐͏̨̛͔̦̟͈̻O̜͎͍͙͚̬̝̣̽ͮ͐͗̀ͤ̍̀͢M̴̡̲̭͍͇̼̟̯̦̉̒͠Ḛ̛̙̞̪̗ͥͤͩ̾͑̔͐ͅṮ̴̷̷̗̼͍̿̿̓̽͐H̙̙̔̄͜: 42 }; is valid JavaScript. It may not be immediately obvious, but the real surprise here is that the Cthulhu-esque property …


This content originally appeared on Mathias Bynens and was authored by Mathias

Fun fact: var foo = { H̹̙̦̮͉̩̗̗ͧ̇̏̊̾Eͨ͆͒̆ͮ̃͏̷̮̣̫̤̣Cͯ̂͐͏̨̛͔̦̟͈̻O̜͎͍͙͚̬̝̣̽ͮ͐͗̀ͤ̍̀͢M̴̡̲̭͍͇̼̟̯̦̉̒͠Ḛ̛̙̞̪̗ͥͤͩ̾͑̔͐ͅṮ̴̷̷̗̼͍̿̿̓̽͐H̙̙̔̄͜: 42 }; is valid JavaScript. It may not be immediately obvious, but the real surprise here is that the Cthulhu-esque property name is not surrounded by quotes. Intrigued by this, and having written about the similar topic of JavaScript identifiers before, I decided to look into valid property names in JavaScript. When do they need to be quoted? When can the quotes be omitted? And in which cases can dot notation be used instead of bracket notation to get or set a property based on its name?


This content originally appeared on Mathias Bynens and was authored by Mathias


Print Share Comment Cite Upload Translate Updates
APA

Mathias | Sciencx (2012-02-29T21:17:54+00:00) Unquoted property names / object keys in JavaScript. Retrieved from https://www.scien.cx/2012/02/29/unquoted-property-names-object-keys-in-javascript/

MLA
" » Unquoted property names / object keys in JavaScript." Mathias | Sciencx - Wednesday February 29, 2012, https://www.scien.cx/2012/02/29/unquoted-property-names-object-keys-in-javascript/
HARVARD
Mathias | Sciencx Wednesday February 29, 2012 » Unquoted property names / object keys in JavaScript., viewed ,<https://www.scien.cx/2012/02/29/unquoted-property-names-object-keys-in-javascript/>
VANCOUVER
Mathias | Sciencx - » Unquoted property names / object keys in JavaScript. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2012/02/29/unquoted-property-names-object-keys-in-javascript/
CHICAGO
" » Unquoted property names / object keys in JavaScript." Mathias | Sciencx - Accessed . https://www.scien.cx/2012/02/29/unquoted-property-names-object-keys-in-javascript/
IEEE
" » Unquoted property names / object keys in JavaScript." Mathias | Sciencx [Online]. Available: https://www.scien.cx/2012/02/29/unquoted-property-names-object-keys-in-javascript/. [Accessed: ]
rf:citation
» Unquoted property names / object keys in JavaScript | Mathias | Sciencx | https://www.scien.cx/2012/02/29/unquoted-property-names-object-keys-in-javascript/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.