- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6704 Articles for Javascript
3K+ Views
JavaScript label statements are used to prefix a label to an identifier. A label can be used with break and continue statement to control the flow more precisely. A label is simply an identifier followed by a colon (:) that is applied to a statement or a block of code. We will see two different examples to understand how to use labels with break and continue.ExampleYou can try to run the following code to use labels to control the flow, with break statementLive Demo document.write("Entering the loop! "); ... Read More
2K+ Views
In this tutorial, we will learn to come out of a switch case in JavaScript. The switch-case statement is the advanced version of the too many complicated if-else statements. Suppose that in the code, you apply too many conditions to the if-else statement; it will become complicated. Users can see the example of too many if-else here. if( condition 1) { // some code } else if( condition 2 ) { // some code for this block } else if( condition 3 ) { // some code for this block } ... Read More
1K+ Views
The purpose of a while loop is to execute a statement or code block repeatedly as long as an expression is true. Once the expression becomes false, the loop terminates.ExampleYou can try to run the following code to learn how to use nested while loopLive Demo var height = 2; var width = 8; var col = 0; var row = 0; document.write("Starting Loop "); while (row < height) { col = 0; while(col < width) { document.write("#"); col++; } document.write(""); row++; } document.write("Loop stopped!");
203 Views
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; }
247 Views
To control the flow in JavaScript, use labels. A label can be used with break and continue statement to control the flow more precisely. A label is simply an identifier followed by a colon (:) that is applied to a statement or a block of code. We will see two different examples to understand how to use labels with break and continue.ExampleYou can try to run the following code to use labels to control the flow, with break statement −Live Demo ... Read More
489 Views
This tutorial will teach us to use a label with the continue statement in JavaScript. In the ES5, we were using the label with the go-to statement to jump over the iteration, but it is not supported in the ES6 version of JavaScript. So, we will use the continue statement to jump over the loop iteration or skip any single iteration.Here are the basic definitions of the label and continue statement.label − It can be any string to give a name or label to the block of code.continue − It is used to jump over the one iteration of the ... Read More
2K+ Views
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; }
645 Views
This tutorial will teach us to use a label with a break statement in JavaScript. The label and break statement are not new in JavaScript, and many of you are familiar with both. The label is a unique string we can use to give the identity to the block of code, loops, switch cases, etc., in JavaScript.We can use the break keyword with the label statement. It stops the execution of the code in the middle.In this tutorial, we will learn to use the label and break statement with the loops, and block of codes.Here are the basic definitions of ... Read More
100 Views
The break statement is used to exit a loop early, breaking out of the enclosing curly braces.ExampleYou can try to run the following code to learn how to use the break statement to come out of a loopLive Demo var x = 1; document.write("Entering the loop "); while (x < 20) { if (x == 5) { break; // breaks out of loop completely } x = x + 1; document.write( x + ""); } document.write("Exiting the loop! ");
287 Views
The break statement is used to break a loop and continue executing the code, which is after the loop.ExampleYou can try to run the following code to break a loop in JavaScriptLive Demo var text = ""; var i; for (i = 0; i < 5; i++) { if (i === 2) { break; } text += "Value: " + i + ""; } document.getElementById("test").innerHTML = text; OutputValue: 0 Value: 1