const-reassignment.js 447 B

12345678910111213141516
  1. test("reassignment to const", () => {
  2. const constantValue = 1;
  3. expect(() => {
  4. constantValue = 2;
  5. }).toThrowWithMessage(TypeError, "Invalid assignment to const variable");
  6. expect(constantValue).toBe(1);
  7. });
  8. test("const creation in inner scope", () => {
  9. const constantValue = 1;
  10. do {
  11. const constantValue = 2;
  12. expect(constantValue).toBe(2);
  13. } while (false);
  14. expect(constantValue).toBe(1);
  15. });