function fn() {
let ax = bx = 110;
ax++;
return ax;
}
fn()
console.log(typeof bx)
console.log(typeof ax)
its answer is // undefined number .
I am very confused, how it is possible. as ax , bx is in scope
>Solution :
When we write let ax = bx = 110;, we are not doing
let ax = 110;
let bx = 110;
In fact there is no keyword in front of bx, and hence it is considered to be from the outer scope. In this case, bx becomes a part of global scope. And hence it is available outside.
PS:
One hacky way to do it in one line:
function fn() {
let [ax,bx] = [110,110];
ax++;
return ax;
}
fn()
console.log(typeof bx)
console.log(typeof ax)