Skip to content

Latest commit

 

History

History
30 lines (27 loc) · 724 Bytes

7-js-objects.md

File metadata and controls

30 lines (27 loc) · 724 Bytes

Objects

A JavaScript object is a collection of named values. The values are written as name : value pairs (name and value separated by a colon).

  • javascript objects are mutable
Creating javascript objects:
  1. Using object literal
var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
  1. Using javascript keyword new
var person = new Object();
person.firstName = "John";
person.lastName = "Doe";
person.age = 50;
person.eyeColor = "blue";
  1. Using Object.create()
const Animal = {
  type: 'Invertebrates',
  displayType: function() {
    console.log(this.type);
  }
};

let animal1 = Object.create(Animal);
animal1.displayType(); // Invertebrates