Found 10711 Articles for Web Development

How to label a block in JavaScript?

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

283 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

381 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

469 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

638 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

402 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

How to define a function in JavaScript?

Srinivas Gorla
Updated on 15-Jun-2020 12:04:16

150 Views

The most common way to define a function in JavaScript is by using the “function” keyword, followed by a unique function name, a list of parameters (that might be empty), and a statement block surrounded by curly braces.SyntaxHere’s the syntax −     Try the following example. It defines a function called sayHello that takes no parameters,    

What is a default constructor in JavaScript?

mkotla
Updated on 12-Jun-2020 14:04:17

670 Views

If a constructor method is not added, then a default constructor should be used. A default constructor is created when nothing is defined.SyntaxHere’s the syntax −constructor() {}The syntax for derived class −constructor(...args) {    super(...args); }

How to show if...else statement using a flowchart in JavaScript?

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

170 Views

The if statement is the fundamental control statement that allows JavaScript to make decisions and execute statements conditionally. Let’s see how to show if…else statement using flowchart in JavaScript.

What is the best way to compare two strings in JavaScript?

Fendadis John
Updated on 08-Jan-2020 09:40:36

11K+ Views

To compare two strings in JavaScript, use the localeCompare() method. The method returns 0 if both the strings are equal, -1 if string 1 is sorted before string 2 and 1 if string 2 is sorted before string 1.ExampleYou can try to run the following code to compare two stringsLive Demo           Compare Strings                      function compareStr() {             var string1 = "World";             var string2 = "World";             var result = string1.localeCompare(string2);             document.getElementById("test").innerHTML = result;          }          

Advertisements