Found 9054 Articles for Front End Technology

How to use JavaScript to show a confirm message?

Abhishek Kumar
Updated on 10-Nov-2022 08:21:44

6K+ Views

In this tutorial, we will learn how to use JavaScript to show a confirm message. We use window.confirm() method of JavaScript to show a confirm message. A confirm message is enclosed in a confirm dialog box which is a modal window. Such a window takes focus upon being created and doesn’t go out of focus until the user responds to it. Confirmation dialog box in JavaScript A confirm message is a yes/no message for the user that requires immediate attention. A confirmation dialog box usually gets triggered in response to some action requested by the user. This action can be ... Read More

How to call a JavaScript function from an onClick event?

varun
Updated on 08-Jan-2020 10:32:26

1K+ Views

The onClick event is the most frequently used event type, which occurs when a user clicks the left button of the mouse. You can put your validation, warning etc., against this event type.ExampleYou can try to run the following code to call a JavaScript function from an onClick eventLive Demo                                         Click the following button and see result                          

What is the lifetime of JavaScript variables?

Govinda Sai
Updated on 15-Jun-2020 12:14:35

751 Views

The lifetime of a JavaScript variable begins when it is declared −var rank;A local variable will be visible only within a function where it is defined. Function parameters are always local to that function.The completion of a function deletes the local variable.A global variable has a global scope which means it can be defined anywhere in your JavaScript code. Global variables delete when the web browser is closed. However if a new page is loaded in the same browser window, then it remains.Here’s the usage of global variables −ExampleYou can try to run the following code to learn how to ... Read More

What are event handlers in JavaScript?

seetha
Updated on 03-Oct-2019 06:24:02

500 Views

JavaScript's interaction with HTML is handled through events that occur when the user or the browser manipulates a page.When the page loads, it is called an event. When the user clicks a button, that click to is an event. Other examples include events like pressing any key, closing a window, resizing a window, etc.Here are some examples:onclick Event TypeThis is the most frequently used event type, which occurs when a user clicks the left button of his mouse. You can put your validation, warning etc., against this event type.Try the following example.Live Demo               ... Read More

How to label a block in JavaScript?

Ramu Prasad
Updated on 15-Jun-2020 12:13:36

257 Views

A block statement groups zero or more statements. In languages other than JavaScript, it is known as a compound statement.SyntaxHere’s the syntax −{    //List of statements }To add a label to a block, use the following −Identifier_for_label: {    StatementList }Let’s use it for break statement. You can try to run the following code to use labels to control the flow, with break statementExampleLive Demo                    document.write("Entering the loop! ");          outerloop:   // This is the label name          for (var i = ... Read More

Why are "continue" statements bad in JavaScript?

Sravani S
Updated on 08-Jan-2020 10:20:39

553 Views

The usage of “continue” statement makes the code difficult to understand. In most cases, the usage of continue would mean you have an insufficient condition in your loop. To avoid this, you can add it to the condition itself or use if in a loop.But, “continue” is bad if it is used inconsistently or improperly, else it is a useful statement and saves a lot of memory and lines of code.ExampleLet’s see an example of continue statementLive Demo                    var x = 1;          document.write("Entering the loop "); ... Read More

What is onclick event in JavaScript?

vanithasree
Updated on 08-Jan-2020 10:19:53

349 Views

The onClick event is the most frequently used event type, which occurs when a user clicks the left button of the mouse.ExampleYou can put your validation, warning etc., against this event type.Live Demo                                         Click the following button and see result                          

How to show a nested for loop in a flow chart in JavaScript?

Priya Pallavi
Updated on 12-Jun-2020 14:07:10

429 Views

The “for loop” includes initialization, test statement, and iteration statement. You can try to run the following code to show a nested for loop in a flow chart −

What is a block statement in JavaScript?

Nikitha N
Updated on 15-Jun-2020 12:04:58

581 Views

A block statement groups zero or more statements. In languages other than JavaScript, it is known as a compound statement.SyntaxHere’s the syntax −{    //List of statements }Variables with a block get scoped to the containing function. Block statement never introduce scope and using var to declare variables don’t have block scope.var a = 20; {    var b = 40; }Now, when you will print the value of a, it will print 40, not 20. This is because variable declared with a var within the block has the same scope like var before the block.var a = 20; {    var a = 40; } // this prints 40 document.write(a);

What is the difference between break with a label and without a label in JavaScript?

Samual Sam
Updated on 12-Jun-2020 14:05:42

386 Views

Break without labelThe break statement is used to exit a loop early, breaking out of the enclosing curly braces.  The break statement exits out of a loop. ExampleLet’s see an example of break statement in JavaScript without using label −Live Demo                            var x = 1;          document.write("Entering the loop ");                  while (x < 20) {             if (x == 5){                break; // breaks out ... Read More

Advertisements