MIRROR: javascript for 馃悳's, a tiny runtime with big ambitions
1// Test return in class methods
2
3class Test {
4 method1(x) {
5 console.log("Method1: x =", x);
6 if (x > 5) {
7 console.log("Returning early");
8 return;
9 }
10 console.log("After if block");
11 }
12
13 method2(x) {
14 console.log("Method2: x =", x);
15 if (x > 5) {
16 console.log("Returning early with value");
17 return "early";
18 }
19 console.log("After if block");
20 return "normal";
21 }
22}
23
24let t = new Test();
25
26console.log("Test 1:");
27t.method1(3);
28
29console.log("\nTest 2:");
30t.method1(7);
31
32console.log("\nTest 3:");
33let r1 = t.method2(3);
34console.log("Returned:", r1);
35
36console.log("\nTest 4:");
37let r2 = t.method2(7);
38console.log("Returned:", r2);