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 */ 15declare function print(arg:any, arg1?:any):string; 16 17let str:string = "1234567890上下左右中"; 18 19// two const 20print("123" == "123"); 21print(str == "1234567890上下左右中"); 22print("1" == "1") 23print(str[0] == "12") 24 25// one const 26let ans = 0; 27for (let i = 0; i<15; ++i) { 28 let m:string = str[i]; 29 if (m == "1" || m == "上" || m == "国") { 30 ans += 1; 31 } 32} 33print(ans); 34 35// no const 36function foo(flag) { 37 let str = "12"; 38 if (flag) { 39 return str[0]; 40 } else { 41 return str[1]; 42 } 43} 44let left:string = foo(true); 45let right1:string = foo(true); 46let right2:string = foo(false); 47print(left == right1); 48print(left == right2); 49