• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16
17let i = 1;
18let j = 2;
19let b1 = true;
20let b2 = false;
21let r1 = new Object();
22let r2: Object | null = null;
23
24// nullish
25let r3 = r1 ?? r2;
26let r4 = r1 ?? r2 ?? r3;
27
28// logical (and, or)
29let b01 = b1 && b2;
30let b02 = b1 || b2;
31let b03 = b1 && b2 && b01 && b02;
32let b04 = b1 || b2 || b01 || b02;
33let b05 = b1 && b2 || b01 || b02;
34let b06 = b1 || b2 && b01 && b02;
35
36// bitwise (and, or, xor)
37let i01 = i & j;
38let i02 = i ^ j;
39let i03 = i | j;
40let i04 = i & j ^ i & j | i ^ j;
41
42// equality (eq, neq, strict eq, strict neq)
43let b07 = i != j;
44let b08 = i == j;
45let b09 = r1 !== r2;
46let b10 = r1 === r2;
47
48// relational (less, greater, less eq, greater eq), instanceof
49let b12 = i < j;
50let b13 = i > j;
51let b14 = i <= j;
52let b15 = i >= j;
53let b16 = r1 instanceof Object;
54
55// shift (left, right, unsigned right)
56let b17 = i >> j;
57let b18 = i << j;
58let b19 = i >>> j;
59let b20 = i >> j << i >>> j;
60
61// additive (add, sub)
62let i05 = i + j;
63let i06 = i - j;
64let i07 = i + j - i + j;
65
66// multiplicative (mul, div, mod)
67let i08 = i * j;
68let i09 = i / j;
69let i10 = i % j;
70let i11 = i * j / i % j * i / j;
71
72// mixed, precedence
73let b21 = i * j >>> i - j;
74let b22 = i > j && b1 || b2;
75let b23 = i * j + i >> j < i != b1 & b2 ^ b1 | b2 && b1 || b2;
76let b24 = b1 || b2 && b1 | b2 ^ b1 & b2 == i >= j << i - j % i;
77let b25 = r1 ?? b1 != b2 | i <= j;
78