···11+// Test var hoisting behavior
22+// In JavaScript, 'var' declarations are hoisted to the function scope (or global scope)
33+// regardless of where they are declared within blocks
44+55+console.log("=== Test 1: Basic var hoisting in blocks ===");
66+{
77+ var x = 10;
88+}
99+console.log("x should be 10:", x);
1010+1111+console.log("\n=== Test 2: var in nested blocks ===");
1212+{
1313+ {
1414+ {
1515+ var y = 20;
1616+ }
1717+ }
1818+}
1919+console.log("y should be 20:", y);
2020+2121+console.log("\n=== Test 3: var in if blocks ===");
2222+if (true) {
2323+ var z = 30;
2424+}
2525+console.log("z should be 30:", z);
2626+2727+console.log("\n=== Test 4: var in function scope ===");
2828+function testFunc() {
2929+ {
3030+ var a = 40;
3131+ }
3232+ return a;
3333+}
3434+console.log("a inside function should be 40:", testFunc());
3535+3636+console.log("\n=== Test 5: var in for loop ===");
3737+for (var i = 0; i < 3; i++) {
3838+ // loop body
3939+}
4040+console.log("i should be 3:", i);
4141+4242+console.log("\n=== Test 6: var in with statement ===");
4343+var obj = { prop: 100 };
4444+with (obj) {
4545+ var w = 50;
4646+}
4747+console.log("w should be 50:", w);
4848+4949+console.log("\n=== Test 7: Multiple var declarations in different blocks ===");
5050+{
5151+ var m = 1;
5252+}
5353+{
5454+ var n = 2;
5555+}
5656+console.log("m should be 1, n should be 2:", m, n);
5757+5858+console.log("\n=== Test 8: var reassignment across blocks ===");
5959+{
6060+ var p = 100;
6161+}
6262+{
6363+ p = 200;
6464+}
6565+console.log("p should be 200:", p);
6666+6767+console.log("\n=== Test 9: var in while loop ===");
6868+var count = 0;
6969+while (count < 2) {
7070+ var q = count;
7171+ count++;
7272+}
7373+console.log("q should be 1:", q);
7474+7575+console.log("\n=== Test 10: Function scope isolation ===");
7676+function outer() {
7777+ {
7878+ var funcVar = 77;
7979+ }
8080+ return funcVar;
8181+}
8282+console.log("funcVar inside function should be 77:", outer());
8383+// funcVar should not be accessible here (would be undefined in global scope)
8484+8585+console.log("\n=== Test 11: var vs let comparison ===");
8686+{
8787+ var varTest = "var-value";
8888+ let letTest = "let-value";
8989+}
9090+console.log("varTest should be 'var-value':", varTest);
9191+try {
9292+ console.log("letTest should cause error:", letTest);
9393+} catch (e) {
9494+ console.log("letTest correctly not accessible (block-scoped)");
9595+}
9696+9797+console.log("\n=== All var hoisting tests completed ===");