comma-operator.js 530 B

123456789101112131415161718192021222324
  1. test("inside parenthesis", () => {
  2. expect((1, 2, 3)).toBe(3);
  3. expect((1, 2 + 3, 4)).toBe(4);
  4. });
  5. test("with post-increment operator", () => {
  6. let foo = 0;
  7. foo = (foo++, foo);
  8. expect(foo).toBe(1);
  9. });
  10. test("with assignment operator", () => {
  11. var a, b, c;
  12. expect(((a = b = 3), (c = 4))).toBe(4);
  13. expect(a).toBe(3);
  14. expect(b).toBe(3);
  15. expect(c).toBe(4);
  16. var x, y, z;
  17. expect((x = ((y = 5), (z = 6)))).toBe(6);
  18. expect(x).toBe(6);
  19. expect(y).toBe(5);
  20. expect(z).toBe(6);
  21. });