1/* 2 * Copyright (c) 2024-2025 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 17const num = 121; 18 19const num2 = 11 * 11; 20 21function getSeq(num: number) { 22 return num * num; 23} 24 25switch (num) { 26 case 1: 27 console.log('First match'); 28 break; 29 case 1: 30 console.log('First match'); 31 break; 32 case num2: 33 console.log('Second match'); 34 break; 35 case getSeq(11): 36 console.log('Third match'); 37 break; 38 default: 39 console.log('No match'); 40} 41 42const str = 'abc'; 43 44switch (abc) { 45 case 'abc': 46 console.log('abc match'); 47 break; 48 case 'bcd': 49 console.log('bcd match'); 50 break; 51 case 'bcd': 52 console.log('bcd match'); 53 break; 54 case 'abc' 55 console.log('abc match'); 56 break; 57 default: 58 console.log('No match'); 59} 60 61enum Test{ 62 TEST1,TEST2,TEST3 63} 64 65const value = Test.TEST1; 66 67switch (value) { 68 case Test.TEST1: 69 console.log('TEST1 match'); 70 break; 71 case Test.TEST2: 72 console.log('TEST2 match'); 73 break; 74 case Test.TEST3: 75 console.log('TEST3 match'); 76 break; 77 case Test.TEST1: 78 console.log('TEST1 match'); 79 break; 80 default: 81 console.log('No match'); 82} 83 84