Message from JavaScript discussions

May 2018

— Was just curious why people still use promises and u just answered it

— 


var a = 5;

function lol() {
var a = 10;
console.log(this.a)

function kek() {
console.log(this.a)
}
kek()
}

— 

lol()

outputs
5
5

— Can somebody explain me why?
First console log prints 5 that makes sense as call site for lol function is global scope but for kek function call site is lol() then why its logging 5 instead of 10?

Message permanent page

— Why you put this?

— SetProperty is used for css variables not for css properties, you seem confused about the two

— It can set both

— Just trying to figure out how

this

works

— Btw I got my answer 😄

— Global scope?

— This (in the absence of new, bind, call or apply magic) refers to the object in which the function was called.

If there is no object, then the default object is used. For web browsers, that object is window.

Message permanent page

— Is it in spec?