A peculiar problem in JS

by currentricity

JavaScript has a peculiar problem.

In lot of languages the following or a variation of the following will pass as valid code:

var somearray = { 'key' : 'value' };

But in JS this will lead to a missing : after property id error during compile time and subsequently during run time too.

What’s the correct javascript way of doing the same?

var somearray = {};
somearray['key'] = 'value';

Also, on a side note, Liferay makes localization of pure JS code quite easy by exposing the following API


The key-value pair should find an entry in the Liferay’s Languages-*.xml
You just need to pass the key and Liferay will pick up the locale on its own. You can also make an ajax call to