Search code examples
angulartypescriptlabeled-statements

Do we have labeled Statements in Typescript similar to what we have in JS?


I found this very interesting that we can break or continue a loop in Javascript. Do we have a similar concept in Typescript (Angular)?

let str = '';

loop1:
for (let i = 0; i < 5; i++) {
  if (i === 1) {
    continue loop1;
  }
  str = str + i;
}

console.log(str);
// expected output: "0234"

Solution

  • The answer is yes, it is working in typescript. However, it is a JS native statement that is compatible with typescript and is not part of typescript statements.