Front End Technology Articles

Page 18 of 652

How to write a JavaScript function to get the difference between two numbers?

Arjun Thakur
Arjun Thakur
Updated on 11-Mar-2026 9K+ Views

Use Math.abs() inside a JavaScript function to get the difference between two numbers in JavaScript.ExampleYou can try to run the following code to get the difference of numbers                    var num1, num2;          num1 = 50;          num2 = 35;          var difference = function (num1, num2){             return Math.abs(num1 - num2);          }          document.write("Difference = "+difference(num1,num2));              

Read More

How to use JavaScript to hide a DIV when the user clicks outside of it?

Rishi Raj
Rishi Raj
Updated on 11-Mar-2026 1K+ Views

To hide a div when the user clicks outside of it, try to run the following codeExample                    window.onload = function(){             var hideMe = document.getElementById('hideMe');             document.onclick = function(e){                if(e.target.id !== 'hideMe'){                   hideMe.style.display = 'none';                }             };          };             Click outside this div and hide it.    

Read More

How to break a loop in JavaScript?

Ankitha Reddy
Ankitha Reddy
Updated on 11-Mar-2026 446 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 JavaScript                          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

Read More

What are label statements in JavaScript?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 4K+ 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 statement                    document.write("Entering the loop! ");     ...

Read More

What is onclick event in JavaScript?

vanithasree
vanithasree
Updated on 11-Mar-2026 683 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.                                         Click the following button and see result                          

Read More

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

Samual Sam
Samual Sam
Updated on 11-Mar-2026 620 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 −                            var x = 1;          document.write("Entering the loop ");                  while (x < 20) {             if (x == 5){                break; // breaks out of ...

Read More

What is the lifetime of JavaScript variables?

Govinda Sai
Govinda Sai
Updated on 11-Mar-2026 1K+ 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

How to call a JavaScript function from an onClick event?

varun
varun
Updated on 11-Mar-2026 2K+ 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 event                                         Click the following button and see result                          

Read More

How to call a JavaScript function from an onmouseover event?

varma
varma
Updated on 11-Mar-2026 2K+ Views

The onmouseover event triggers when you bring your mouse over any element.ExampleYou can try to run the following example to learn how to call a JavaScript function from onmouseover event                                         Bring your mouse inside the division to see the result:                 This is inside the division          

Read More

How to create a dialog with &ldquo;yes&rdquo; and &ldquo;no&rdquo; options in JavaScript?

Anvi Jain
Anvi Jain
Updated on 11-Mar-2026 3K+ Views

No, you cannot create a dialog box with “yes” or “no”. A confirmation dialog box in JavaScript has “Ok” and “Cancel” button.To create a dialog with “yes” or “nor”, use a custom dialog box.Example                          function functionConfirm(msg, myYes, myNo) {             var confirmBox = $("#confirm");             confirmBox.find(".message").text(msg);             confirmBox.find(".yes, .no").unbind().click(function() {                confirmBox.hide();             });           ...

Read More
Showing 171–180 of 6,518 articles
« Prev 1 16 17 18 19 20 652 Next »
Advertisements