var x = 1;
if (x === 1) {
var x = 3;
console.log(x);
// Expected output: 3
}
console.log(x);
// Expected output: 3
Can someone please explain this: in the loop, x
should be printed as 3
because the condition is satisfied but out of the loop, the last line should print 1
because it's out of loop. However, the output is 3
. Sorry if it's a dumb question – I am new to JS.
Q) Also can you please let me know good website for a code dry run?