Found 10711 Articles for Web Development

How do you reverse a string in place in JavaScript?

Shubham Vora
Updated on 26-Jul-2022 07:37:53

2K+ Views

In this tutorial, we will learn to reverse a string in place in JavaScript. How to reverse a string is one of the most popular questions asked in the interview of freshers. It’s an easy task but the interviewer can be tricky and make the same question difficult for you. For example, what if the interviewer asks you to write a pseudo code to reverse a string in place without using the extra space? You should have an answer ready in your mind for this kind of tricky question.There are lots of ways to reverse a string. As developers develop ... Read More

How to show a while loop using a flow chart in JavaScript?

Sai Subramanyam
Updated on 30-Jul-2019 22:30:21

200 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. Let’s see how to show while loop using flowchart in JavaScript −

How to show for loop using a flowchart in JavaScript?

Lakshmi Srinivas
Updated on 12-Jun-2020 13:58:53

711 Views

The “for” loop includes loop initialization where we initialize our counter to a starting value. The initialization statement is executed before the loop begins, the test statement which will test if a given condition is true or not. If the condition is true, then the code given inside the loop will be executed, otherwise, the control will come out of the loop.At the end comes the iteration statement where you can increase or decrease your counter. Let us see how to show for loop using flowchart in JavaScript −

What is an alert box in JavaScript?

Krantik Chavan
Updated on 12-Jun-2020 13:58:13

1K+ Views

An alert dialog box is mostly used to give a warning message to the users. For example, if one input field requires to enter some text but the user does not provide any input, then as a part of validation, you can use an alert box to give a warning message.Nonetheless, an alert box can still be used for friendlier messages. Alert box gives only one button "OK" to select and proceed.ExampleYou can try to run the following code to learn how to add an alert box −Live Demo                                         Click the following button to see the result:                          

How to validate a date pattern in JavaScript?

Shubham Vora
Updated on 31-Oct-2022 11:49:44

416 Views

In this tutorial, we will learn how to validate a date pattern in JavaScript. The Date object in JavaScript represents a single point in time in a platform-independent way. It carries a number representing time in milliseconds since January 1, 1970, at 00:00:00. (UTC). The Date object can format differently, so it is essential to validate a date pattern before using it. In this tutorial, we will discuss two ways to validate a date pattern in JavaScript − Using the getTime() method Using the Date constructor and split() method Validate a Date Pattern using the getTime() Method In ... Read More

How to use window.location to redirect to a different URL with JavaScript?

Nishtha Thakur
Updated on 12-Jun-2020 13:43:23

383 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

What are label statements in JavaScript?

karthikeya Boyini
Updated on 08-Jan-2020 09:16:48

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

How to come out of a switch case in JavaScript?

Shubham Vora
Updated on 23-Aug-2022 09:53:14

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

How to use nested while loop in JavaScript?

Swarali Sree
Updated on 08-Jan-2020 09:15:17

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!");          

Why doesn't JavaScript have a goto statement?

Samual Sam
Updated on 12-Jun-2020 13:41:12

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; }

Advertisements