Page MenuHomePhorge

test_define_property_strict.js
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

test_define_property_strict.js

"use strict";
// Test Object.defineProperty() in strict mode
const object = {};
Object.defineProperty(object, "foo", {
value: 42,
writable: false,
});
console.log("object.foo =", object.foo);
// Try to modify in strict mode (should throw)
try {
object.foo = 77;
console.log("FAIL: Should have thrown an error");
} catch (e) {
console.log("PASS: Correctly throws in strict mode");
console.log("object.foo still =", object.foo);
}
// Test non-configurable property
const obj2 = {};
Object.defineProperty(obj2, "bar", {
value: "hello",
configurable: false
});
try {
obj2.bar = "world";
console.log("FAIL: Should have thrown an error for non-configurable");
} catch (e) {
console.log("PASS: Correctly throws for non-configurable in strict mode");
console.log("obj2.bar still =", obj2.bar);
}
// Test enumerable
const obj3 = {};
Object.defineProperty(obj3, "hidden", {
value: "secret",
enumerable: false
});
Object.defineProperty(obj3, "visible", {
value: "public",
enumerable: true
});
console.log("\nKeys of obj3:", Object.keys(obj3));
console.log("Expected: only 'visible' should be in keys");
console.log("\nAll strict mode tests passed!");

File Metadata

Mime Type
application/javascript
Expires
Fri, Mar 27, 9:17 AM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
512301
Default Alt Text
test_define_property_strict.js (1 KB)

Event Timeline