How can I use goto statement in JavaScript?

JavascriptWeb DevelopmentFront End Technology

JavaScript goto statement is a reserved keyword. Generally, according to web standards it isn’t considered a good practice to use goto statement.

Using goto with JavaScript preprocessing is still considered good as shown below.

var a = 0;
[lbl] beginning:
console.log("Demo Text!");
a++;
if(i < 424) goto beginning;

The above code gets translated like the following −

var a = 0;
beginning: while(true) {
   console.log("Demo Text!");
   a++;
   if(i < 424) continue beginning;
      break;
}
raja
Published on 22-Jan-2018 13:30:05
Advertisements