0

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"
navnath
  • 3,548
  • 1
  • 11
  • 19
Ramin
  • 19
  • 6
  • 1
    Yes, try running your code [here](https://www.typescriptlang.org/play) – navnath Oct 15 '21 at 12:09
  • 1
    Most valid JS statements are valid TS statements too. There does exist some [edge cases](https://stackoverflow.com/q/20759532/6513921) though. – ruth Oct 15 '21 at 12:22
  • ok, it is working, is it native js that is used in typescript or typescript statements? – Ramin Oct 16 '21 at 22:11

1 Answers1

0

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.

Ramin
  • 19
  • 6