variable-declaration.js 552 B

12345678910111213141516171819202122232425
  1. load("test-common.js");
  2. try {
  3. const constantValue = 1;
  4. assertThrowsError(() => {
  5. constantValue = 2;
  6. }, {
  7. error: TypeError,
  8. message: "Invalid assignment to const variable"
  9. });
  10. assert(constantValue === 1);
  11. // Make sure we can define new constants in inner scopes.
  12. const constantValue2 = 1;
  13. do {
  14. const constantValue2 = 2;
  15. assert(constantValue2 === 2);
  16. } while (false);
  17. assert(constantValue2 === 1);
  18. console.log("PASS");
  19. } catch (e) {
  20. console.log("FAIL: " + e);
  21. }