variable-declaration.js 569 B

123456789101112131415161718192021222324
  1. try {
  2. const constantValue = 1;
  3. try {
  4. constantValue = 2;
  5. assertNotReached();
  6. } catch (e) {
  7. assert(e.name === "TypeError");
  8. assert(e.message === "Assignment to constant variable");
  9. assert(constantValue === 1);
  10. }
  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. }