• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#  The comma operator ``,`` is supported only in ``for`` loops
2
3Rule ``arkts-no-comma-outside-loops``
4
5**Severity: error**
6
7ArkTS supports the comma operator ``,`` only in ``for`` loops. Otherwise,
8it is useless as it makes the execution order harder to understand.
9
10
11## TypeScript
12
13
14```
15
16    for (let i = 0, j = 0; i < 10; ++i, j += 2) {
17        console.log(i)
18        console.log(j)
19    }
20
21    let x = 0
22    x = (++x, x++) // 1
23
24```
25
26## ArkTS
27
28
29```
30
31    for (let i = 0, j = 0; i < 10; ++i, j += 2) {
32        console.log(i)
33        console.log(j)
34    }
35
36    // Use explicit execution order instead of the comma operator:
37    let x = 0
38    ++x
39    x = x++
40
41```
42
43
44