Zhen Zhang


Eloquent JS: Data Structure: Objects and Arrays

June 13, 2026

1.Almost all JavaScript values have properties. The exceptions are null and undefined. If you try to access a property on one of these nonvalues you get an error.

2.Whereas value.x fetches the property of value named "x", value[x] takes the value of the variable named x and use that, converted to a string, as the property name.

3.Properties that contain functions are generally called methods of the value they belong to, as in "toUppercase is a method of a string".

4.Properties whose name aren't valid binding names or valid numbers must be quoted 5.There's an Object.assign function that copies all properties from one object into another:

let objectA = {a:1, b:2};
  object.assign(objectA, {b:3, c:4});
  console.log(objectA);
  //{a:1, b:3, c:4}
6.with objects, there is a difference between having two references to the same object and having two different objects that contain the same properties.

7.Similarly, though a const binding to an object can itself not be changed and will contine to point at the same object, the contents of that object might change.

const score = {visitors:0, home:0};
//This is okay
score.visitors=1;
//This isn't allowed
score={visitors:1, home:1};
8.When you compare objects with JavaScript == operator, it compares by identity it will produce true only if both objects are precisely the same value. Comparing different objects will return false, even if they have identical properties.

9.
function tableFor(event, journal){
  let table = [0, 0, 0, 0];
  for(let entry of journal){
    let index = 0;
    if(entry.events.includes(event)) index++;
    if(entry.squiarel) index +=2;
    table[index]++;
  }
  return table;
}
10.The corresponding methods for adding and removing things at the start of a array are called unshift and shift.(indexOf, lastIndexOf, slice(2, 4), concat())

11.String method: slice(), indexOf(), tim(), padStart(3, "0"), split(""), join(""), repeat(3)

12.When such a function is called the rest parameter is bound to an array containing all further arguments. If there are other parameters before it, their values aren't part of that array
console.log(max(...numbers));
max(9, ...numbers, 2)
["will", ...words, "understand"]
{...cordinates, y:5, z:1}
13.Many languages will stop you, or at least warn you, when you are defining a binding with a value that is already taken, JavaScript does this for bingdings you declared with let or const but --perverstly--not for standard bindings nor for bindings declared with var of function.

14.Note that if you try to destructure null or undefined, you got an error, much as you would if you directly try to access a property of those values.

15.
Object?.property
"string".notAMethod?()
arrayProp?.[0]
The expression a?.b means the same as a.b when a isn't null or undefined. when it is, it evaluates to undefined


About Privacy Home