3 ms·
var is global scope, const is block scoped... <script> var x = 1; if(x < 5) { // now y is global (window.y can be accessed everywhere) // using c
by sandreas 2y ago
var is global scope, const is block scoped...
<script>
var x = 1;
if(x < 5) {
// now y is global (window.y can be accessed everywhere)
// using const y = x * 2 would be inaccessible outside the if block
var y = x * 2;
console.log('double x is: " + y);
}
</script>
Besides that, var is "pulled" upwards, as if it was the first line in the function. That may have side effects.