Wednesday, 21 September 2022

js basic code understanding

Basic concept



STEP1 -  we created a class by {}, then created vars and methods () inside the class. properties are assigned inside a constructor() method.
                    class Car {
  constructor(name) {
    this.brand = name;
  }
  
  present() {
    return 'I have a ' + this.brand;
  }
}

STEP2 - create instance of class. 
        const mycar = new Car("Ford");

STEP3 - we call class method by class instance.
        mycar.present();


class Car {
  constructor(name) {
    this.brand = name;
  }
  
  present() {
    return 'I have a ' + this.brand;
  }
}

const mycar = new Car("Ford");
mycar.present();


ES6 Variables

  Block scope -  Block scoping means declaring a variable, not just inside a function, but around any curly brackets like if statements or ...