Page MenuHomePhorge

test_strict_function.cjs
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

test_strict_function.cjs

// Test function-level strict mode
// Based on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode
// Non-strict code
let globalVar = 10;
console.log("Non-strict global:", globalVar);
// Function with strict mode
function strictFunction() {
"use strict";
// This should work - accessing outer scope
console.log("Accessing outer scope:", globalVar);
// This should fail - undeclared variable
try {
undeclaredVar = 20;
console.log("FAIL: Should have thrown error in strict function");
} catch (e) {
console.log("PASS: Strict mode in function works");
}
}
strictFunction();
// Non-strict function - should allow undeclared vars (though not recommended)
function nonStrictFunction() {
// Note: In this implementation, undeclared vars might still error
// as they create implicit globals which is generally an error
console.log("PASS: Non-strict function executed");
}
nonStrictFunction();
// Arrow function with strict mode
const strictArrow = () => {
"use strict";
try {
newVar = 30;
console.log("FAIL: Arrow function strict mode didn't work");
} catch (e) {
console.log("PASS: Strict mode in arrow function works");
}
};
strictArrow();
console.log("\nFunction-level strict mode tests completed!");

File Metadata

Mime Type
application/javascript
Expires
Fri, Mar 27, 4:00 AM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
512369
Default Alt Text
test_strict_function.cjs (1 KB)

Event Timeline