THIS keyword

 

const stud={

    name:"abhii",
    age:20,
    math:97,
    eng:98,
    sci:96,
    getAvg(){
        let avg=(eng+math+sci)/3;
        console.log(avg);
    }
}
console.log(stud.getAvg());




const stud={
    name:"abhii",
    age:20,
    math:97,
    eng:98,
    sci:96,
    getAvg(){
        let avg=(this.eng+this.math+this.sci)/3;
        console.log(avg);
    }
}
console.log(stud.getAvg());



THIS KEYWORD INSIDE THE OBJECT AND METHOD

const stud={
    name:"abhii",
    age:20,
    math:97,
    eng:98,
    sci:96,
    getAvg(){
        console.log(this);
        let avg=(this.eng+this.math+this.sci)/3;
        console.log(avg);
    }
}





THIS KEYWORD OUTSIDE THE OBJECT

function getAvg(){
    console.log(this);
}
getAvg();









Comments

Popular posts from this blog

Callback Hell

TODO list with DOM

Refactoring callback hell code