Andre Liem

JavaScript Tidbit #1 – object keys and single quotes

Well it’s official, I let my personal blog get dated… as it happens when you have a “busy” life. That being said, my summer resolution is to post up all the things I learn and feel will be useful for the web development community. Instead of crafting  lengthy long posts which take a while to prepare, I’ve decided to take the microblog approach and  share daily learnings or concepts I’ve recently found useful to be reminded about.

Like a lot of web developers I have been using JavaScript a lot… and as a result have been reading a lot about this seemingly mysterious yet very powerful language. So here is a small cute little thing you might not realize about JavaScript and objects.


Notice how the second version contains key names with quotes and the first doesn’t? It’s a small thing, but lots of people new or old to JS don’t know why you need quotes or not. The short answer is that it generally does not matter and you might as well not use them, unless you are naming the key after a reserved JS word.

This means you could also do something like this:

The name theList in this case serves as the key name and as the variable value. You would probably want to avoid doing this in practice and instead do this:

So that’s my learning for today. It’s nothing groundbreaking but a nice small piece of knowledge to know about JS.

Leave a Reply

Your email address will not be published. Required fields are marked *