- Trending Categories
- 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 6685 Articles for Javascript
382 Views
You might have encountered a situation where you clicked a URL to reach a page X but internally you were directed to another page Y. It happens due to page redirection.It is quite simple to do a page redirect using JavaScript on the client side. To redirect your site visitors to a new page, you just need to add a line in your head section as follows −ExampleYou can try to run the following code to learn how to use window.location to redirect to another URL. Here, we will redirect to the home pageLive Demo ... Read More
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
2K+ 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!");
227 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; }
278 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
522 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; }
711 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
115 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! ");