ladybird/Libraries/LibJS/Tests/variable-declaration.js

27 lines
594 B
JavaScript
Raw Normal View History

load("test-common.js");
try {
2020-04-13 14:11:09 +01:00
const constantValue = 1;
try {
2020-04-13 14:11:09 +01:00
constantValue = 2;
assertNotReached();
} catch (e) {
assert(e.name === "TypeError");
assert(e.message === "Assignment to constant variable");
2020-04-13 14:11:09 +01:00
assert(constantValue === 1);
}
// Make sure we can define new constants in inner scopes.
2020-04-13 14:11:09 +01:00
const constantValue2 = 1;
do {
const constantValue2 = 2;
assert(constantValue2 === 2);
} while (false);
assert(constantValue2 === 1);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}