MIRROR: javascript for 馃悳's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 48 lines 1.3 kB view raw
1// Test function-level strict mode 2// Based on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode 3 4// Non-strict code 5let globalVar = 10; 6console.log("Non-strict global:", globalVar); 7 8// Function with strict mode 9function strictFunction() { 10 "use strict"; 11 12 // This should work - accessing outer scope 13 console.log("Accessing outer scope:", globalVar); 14 15 // This should fail - undeclared variable 16 try { 17 undeclaredVar = 20; 18 console.log("FAIL: Should have thrown error in strict function"); 19 } catch (e) { 20 console.log("PASS: Strict mode in function works"); 21 } 22} 23 24strictFunction(); 25 26// Non-strict function - should allow undeclared vars (though not recommended) 27function nonStrictFunction() { 28 // Note: In this implementation, undeclared vars might still error 29 // as they create implicit globals which is generally an error 30 console.log("PASS: Non-strict function executed"); 31} 32 33nonStrictFunction(); 34 35// Arrow function with strict mode 36const strictArrow = () => { 37 "use strict"; 38 try { 39 newVar = 30; 40 console.log("FAIL: Arrow function strict mode didn't work"); 41 } catch (e) { 42 console.log("PASS: Strict mode in arrow function works"); 43 } 44}; 45 46strictArrow(); 47 48console.log("\nFunction-level strict mode tests completed!");