Actually when you do this: x = 2 You are declaring the variable.
That's why: x = 2 var y = x + 1 console.log(y) // 3
Maybe something like this will help to understand better your point:
console.log(x) // undefined x = 2 var y = x + 1 console.log(y) // 3 var x;
console.log(x) // error x = 2 var y = x + 1 console.log(y)
I came back over and over to this topic and always find new thigs ;)
yeah, some part of JS is so confusing 🤷 Thanks for a detailed example!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Actually when you do this:
x = 2
You are declaring the variable.
That's why:
x = 2
var y = x + 1
console.log(y) // 3
Maybe something like this will help to understand better your point:
console.log(x) // undefined
x = 2
var y = x + 1
console.log(y) // 3
var x;
console.log(x) // error
x = 2
var y = x + 1
console.log(y)
I came back over and over to this topic and always find new thigs ;)
yeah, some part of JS is so confusing 🤷 Thanks for a detailed example!