ladybird/Libraries/LibJS/Tests/variable-declaration.js
Brian Gianforcaro 0d41e542b7 LibJS: Throw on assignment of an const variable
Was stubbed out as an assert, should be handled with a runtime exception.
2020-04-13 01:12:31 +02:00

25 lines
486 B
JavaScript

try {
const ConstantValue = 1;
try {
ConstantValue = 2;
} catch (e) {
assert(e.name === "TypeError");
assert(e.message === "Assignment to constant variable");
assert(ConstantValue === 1);
}
// Make sure we can define new constants in inner scopes.
//
const ConstantValue2 = 1;
do
{
const ConstantValue2 = 2;
}
while (false)
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}