Object and list literals
Object literals listkey: value pairs in curly braces. List literals list values in square brackets. Both can be nested and both allow a trailing comma.
- Object keys are bare identifiers. Quoted keys such as
"brand": "Honda"aren’t supported. - Keys must be unique within a single object literal.
- Values can be any expression, including variables and calculations:
{ total: price * quantity }.
String interpolation
Inside a string,${expression} evaluates any expression and inserts the result:
"a ${"b ${c}"}".
Values are rendered as follows:
To include a literal
${ in a string, escape the dollar sign: "Price: \${amount}".
Reading object properties
Use dot notation to read a property:- Reading a property that doesn’t exist returns
null. It isn’t an error. - Reading a property of anything other than an object, such as a string or
null, is an error.
Reading list elements
Use square brackets with a zero-based index to read a list element:- The index must be an integer.
- An index outside the list is an error, for example
List index 3 is out of bounds (list has 3 items).
orders[0].items[2].price.