Javascript Notes: 01 – Objects

Reference types:

  • Object
  • Array
  • Function
An object in Javascript is like someone in real life. A person has name, age, address, phone number ans so on. These are properties of a person. Each property would be a variable. These properties could all be in one object.
For example:
let name = ‘Nick’;
let age = 25;
Change to an object (The curly bracket { } is called an object literal)
let person = {
    name: ‘Nick’,
    age: 30
}
 
console.log(person);
Two ways to work with these properties, let’s say if we want to change the name of the person. We would use (Dot Notation or Bracket Notation). Dot Notation is cleaner.
let person = {
    name: ‘Nick’,
    age: 30
}
 
//Dot Notation
person.name = ‘John’;
 
//Bracket Notation
person[‘name’] = ‘Mary’;
 
console.log(person.name);