global-var-let-const.js 556 B

123456789101112131415161718192021
  1. var foo = 1;
  2. let bar = 2;
  3. const baz = 3;
  4. test("behavior of program-level var/let/const", () => {
  5. expect(foo).toBe(1);
  6. expect(bar).toBe(2);
  7. expect(baz).toBe(3);
  8. expect(globalThis.foo).toBe(1);
  9. expect(globalThis.bar).toBeUndefined();
  10. expect(globalThis.baz).toBeUndefined();
  11. globalThis.foo = 4;
  12. globalThis.bar = 5;
  13. globalThis.baz = 6;
  14. expect(foo).toBe(4);
  15. expect(bar).toBe(2);
  16. expect(baz).toBe(3);
  17. expect(globalThis.foo).toBe(4);
  18. expect(globalThis.bar).toBe(5);
  19. expect(globalThis.baz).toBe(6);
  20. });