Why doesn't JavaScript have a goto statement?


JavaScript has a goto statement, which is a reserved keyword. It isn’t popular since it is not needed in JavaScript. Generally, it isn’t considered a good practice to use a 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;
}

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 12-Jun-2020

183 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements