Create a small record with named fields.

Object Literals

object_literal.js
const name = "Ada";
const score = ({ name: name, points: 7 }).points;
const label = ({ name: name, points: 7 }).name + ":" + score;

console.log("name=" + name);
console.log("score=" + score);
console.log("label=" + label);

Build a Small Record

  1. name starts as Ada.
  2. The object stores name and points.
  3. Reading .points gives 7.
  4. Reading .name helps build Ada:7. | Property | Value | | --- | --- | | name | Ada | | points | 7 | | label | Ada:7 |
object-literal An object literal groups related values under property names. Reading those properties gives each field back as a normal value.

Exercise: object_literal.js

Create an object with name and points, then print the score and a name-score label