How to use switch statement with strings in TypeScript

1 Answer

0 votes
function main(): void {
  const str: string = "TypeScript";

  switch (str) {
    case "Foo":
      console.log("Foo");
      break;
    case "Wii":
      console.log("Wii");
      break;
    case "TypeScript":
      console.log("TypeScript");
      break;
    case "YYI":
      console.log("YYI");
      break;
    default:
      console.log("No match found.");
  }
}

main();



/*
run:

"TypeScript"

*/

 



answered Jul 1, 2025 by avibootz

Related questions

1 answer 134 views
5 answers 285 views
1 answer 100 views
1 answer 87 views
1 answer 101 views
1 answer 90 views
1 answer 87 views
...