summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Tests/variable-declaration.js
blob: 258b8dbd1aeba0146e1ba45530d9525f71cbdd5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
load("test-common.js");

try {

    const constantValue = 1;
    assertThrowsError(() => {
        constantValue = 2;
    }, {
        error: TypeError,
        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;
        assert(constantValue2 === 2);
    } while (false);
    assert(constantValue2 === 1);

    console.log("PASS");
} catch (e) {
    console.log("FAIL: " + e);
}