Is this the right way to declare a static Javascript map of String keys and String values?
That's a fine object literal, yes. Though, there is nothing really "static" in JavaScript (only the scope of the myMap
variable which you declared with var
, but not it's value).
all keys and values will be html escaped for special characters
That sounds unnecessary, unless you expect the strings to be written into html markup (and there are better ways). If you just escaped them since the script is included in a html document, it was useless - the only thing that needs to be escaped in inline scripts is the sequence </script>
. You just have to string-escape them (i.e. escape backslashes and quotes).