The variable errorTypes
is an object literal . :
Separates the property name of an object (number) from its value. If you are familiar with hash tables in other languages, this structure is a similar concept. For example, in PHP it can be represented as an associative array.
You can do:
var errorTypes = { 0: "Unknown error", 1: "Permission denied", 2: "Position is not available", 3: "Request timeout" }; console.log(errorTypes[0]);
Note that the normal syntax for referencing an object property (using the dot operator) will not work for these numerical properties:
In this case, since numeric property names were used, all of this could be defined as an array instead and accessed in exactly the same way using the []
notation, but with less syntactic control over the keys.
// As an array with the same numeric keys var errorTypes = [ "Unknown error", "Permission denied", "Position is not available", "Request timeout" ]; console.log(errorTypes[2]);
source share