What are Label Statements in JavaScript

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

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 statementLive Demo                    document.write("Entering the loop! ");   ... Read More

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

Use Break Statement to Exit Loop in JavaScript

karthikeya Boyini
Updated on 08-Jan-2020 08:34:34

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

Break a Loop in JavaScript

Ankitha Reddy
Updated on 08-Jan-2020 08:31:10

423 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

Setting Background Position in CSS

AmitDiwan
Updated on 08-Jan-2020 07:52:56

71 Views

The CSS background-position property is used to set an initial position for a background image relative to the origin.SyntaxThe syntax of CSS background-position property is as follows −Selector {    background-position: /*value*/ }The following examples illustrate CSS background-position property −Example Live Demo div {    margin: 30px;    padding: 100px;    background-image: url("https://www.tutorialspoint.com/images/C-programming.png"), url("https://www.tutorialspoint.com/images/Swift.png"), url("https://www.tutorialspoint.com/images/xamarian.png");    background-repeat: no-repeat;    background-position: 15% 20%, top, right;    border: 1px solid; } OutputThis gives the following output −Example Live Demo p {    margin: 20px;    padding: 80px;    background-image: url("https://www.tutorialspoint.com/images/dbms.png"), url("https://www.tutorialspoint.com/images/Operating-System.png");   ... Read More

Bitwise XOR Assignment Operator in JavaScript

Abhinaya
Updated on 08-Jan-2020 07:51:50

335 Views

It performs XOR operation on the right operand with the left operand and assigns the result to the left operand.ExampleYou can try to run the following code to learn how to work with Bitwise XOR Assignment OperatorLive Demo                    var a = 2;   // Bit presentation 10          var b = 3;   // Bit presentation 11          document.write("(a ^= b) => ");          document.write(a ^= b);          

Redirect Website After Certain Amount of Time Without JavaScript

Anvi Jain
Updated on 08-Jan-2020 07:06:18

6K+ Views

To redirect from an HTML page, use the META Tag. With this, use the http-equiv attribute to provide an HTTP header for the value of the content attribute. The value of the content is the number of seconds; you want the page to redirect after.Through this, you can automatically redirect your visitors to a new homepage. Set the content attribute to 0, if you want it to load immediately.ExampleThe following is an example of redirecting current page to another page after 2 seconds.Live Demo           Redirection                     This page will redirect in 2 seconds.    

Get Difference Between Two Numbers Using JavaScript Function

Arjun Thakur
Updated on 08-Jan-2020 06:46:47

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 numbersLive Demo                    var num1, num2;          num1 = 50;          num2 = 35;          var difference = function (num1, num2){             return Math.abs(num1 - num2);          }          document.write("Difference = "+difference(num1,num2));              

Return Value from a JavaScript Function

George John
Updated on 08-Jan-2020 06:30:25

2K+ Views

A JavaScript function can have an optional return statement i.e. it’s optional to return a value. This statement should be the last statement in a function.For example, you can pass two numbers in a function and then you can expect the function to return their multiplication to your calling program.ExampleTry the following example. It defines a function that takes two parameters and concatenates them before returning the resultant in the calling program.Live Demo                    function concatenate(first, last){          var full;          full = first ... Read More

Call Parent Window Function from Iframe Using JavaScript

Paul Richard
Updated on 08-Jan-2020 06:27:14

4K+ Views

To call a parent window function, use “window.top”.ExampleYou can try to run the following code to call a parent window function from an iframeLive Demo                    function display(){             alert("Hello World!");          }                      Click          

Advertisements