• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 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
16let str = "Hello World";
17
18// two const
19print("Hello" + "World");
20print(str + "Hello");
21print("" + "" + "123" + "");
22
23// one const
24let strs = ["OD", "Huawei", ""];
25for (let i = 0; i<3; ++i) {
26    let m = strs[i];
27    print("Hello,  " + m);
28}
29
30// no const
31function foo(flag) {
32    let str = ["BUG", "full of bug"];
33    if (flag) {
34        return str[0];
35    } else {
36        return str[1];
37    }
38}
39let left = foo(true);
40let right1 = foo(true);
41let right2 = foo(false);
42print(left + right1);
43print(left + right2);
44print(right2 + right2);
45
46var hex = "0123456789ABCDEF";
47print("%" + hex[(0xF0 >> 4) & 0xf] + hex[0xF0 & 0xf]);