wiki/content/20201113091110-javascript_object_properties.md

916 B

date id title
2020-11-13 3d5c7ec9-30af-4931-b6ab-2caa687f5951 JavaScript Object Properties

Description

Values of the type object are arbitrary collections of properties

Syntax

let tralala = {
  distro: "Arch",
  useWindows: false,
  aListOfRandomThings: ["spoon", "fork", "modem", "keychain"],
};

console.log(tralala.distro);
console.log(tralala.useWindows);
console.log(tralala.aListOfRandomThings);

Invalid binding names

Properties with invalid binding names or numbers must be quoted:

let weirdObject = {
    tralala: "Chipmunk",
    "this is a long binding name with spaces": "Fill in some nonsensse here"
}

console.log(weirdObject)

Non existant property

Reading a non existant property returns undefined

let Object = {
  thisExists: true,
};

console.log(Object.undefinedProperty); // undefined