Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2921592
test_strict_function.cjs
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
test_strict_function.cjs
View Options
// 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
Details
Attached
Mime Type
application/javascript
Expires
Fri, Mar 27, 9:56 AM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
512369
Default Alt Text
test_strict_function.cjs (1 KB)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment