Found 6704 Articles for Javascript

What is the best way to break from nested loops in JavaScript?

Jennifer Nicholas
Updated on 12-Jun-2020 13:16:07

973 Views

The best way to break from nested loops is to use labels. A label can be used with break and continue 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.ExampleYou can try to run the following code to implement Label with a break statement to break from nested loops −Live Demo                    document.write("Entering the loop! ");          outerloop:  // This is the label name          for (var ... Read More

How to use for...in statement to loop through an Array in JavaScript?

Abhishek Kumar
Updated on 10-Nov-2022 08:50:04

136 Views

We use the for...in statement of JavaScript for looping over enumerable properties of an array or object. It is a variety of for loops. Unlike other loop constructs in JavaScript, the for...in loop doesn’t have to bother about the number of iterations. This is because the iteration size is fixed based on the enumerable properties of the object or the number of elements in the array. The "for...in" statement in JavaScript A for...in loop iterates over all the enumerable properties of an object. All the properties that are assigned using a simple assignment operator or by default initializer are considered ... Read More

What is the difference between break and continue statements in JavaScript?

Smita Kapse
Updated on 13-Jun-2020 13:22:14

351 Views

break statementThe break statement is used to exit a loop early, breaking out of the enclosing curly braces.  The break statement exits out of a loop.  Let’s see an example of break statement in JavaScript. The following example illustrates the use of a break statement with a while loop. Notice how the loop breaks out early once x reaches 5 and reaches to document.write (..) statement just below to the closing curly brace, Example                    var x = 1;          document.write("Entering the loop ");         ... Read More

What is Subtraction Operator (-) in JavaScript?

Abhishek
Updated on 06-Jan-2023 12:07:26

1K+ Views

The subtraction operator is also known as the minus operator. It is a binary operator that means it requires at least two operands to operate on. It will not work with a single operand. Generally, the subtraction operator subtracts or minus the value of the second operand from the first operand and returns the result as it is, that means if the result of two numbers subtraction is negative it will return the negative result, else it will return positive result if that’s positive. In this article, we are going to discuss about the subtraction operator in details and its ... Read More

What is 'void' Operator in JavaScript?

Nitya Raut
Updated on 13-Jun-2020 13:15:35

185 Views

The void is an important keyword in JavaScript, which can be used as a unary operator that appears before its single operand, which may be of any type. This operator specifies an expression to be evaluated without returning a value.SyntaxThe syntax of void can be either of the following two −               The most common use of this operator is in a client-side javascript: URL, where it allows you to evaluate an expression for its side-effects without the browser displaying the value of the evaluated expression.Here the expression alert ('Warning!!!') is evaluated but it ... Read More

What is Unary Negation Operator (-) in JavaScript?

Abhishek
Updated on 06-Jan-2023 12:13:33

216 Views

The Unary Negation Operator first converts the operand into a number, and after that it negates. It operates on a single operand. It returns the negation of the operand. A boolean operand is converted to 0 or 1, and then negation is done. Similarly, a number with a base other than decimal is first converted to base 10, then the negation is computed. Syntax The following syntax will show you how you can use the unary negation operator to negate the value of a number − -x Here unary operator (-) negates x. Let us understand the application of ... Read More

What is Less than Operator (<) in JavaScript?

Abhishek
Updated on 08-Nov-2022 05:59:32

310 Views

The less than operator is one of the operators that come under the category of binary operators, which means it requires two operands to operate on. It will return true if the operand on the left side of the operator is less than the operand on the right side. Otherwise, it will return false. The less than operator come under the category of comparison operators that compare two values with each other. In this tutorial, we are going to discuss what is less than an operator in JavaScript and how it works in different situations, with help of code examples. ... Read More

What is if...else if... statement in JavaScript?

Krantik Chavan
Updated on 13-Jun-2020 11:41:16

224 Views

The if...else if... statement is an advanced form of if…else that allows JavaScript to make a correct decision out of several conditions.SyntaxThe syntax of an if-else-if statement is as follows −if (expression 1){    Statement(s) to be executed if expression 1 is true } else if (expression2){    Statement(s) to be executed if expression 2 is true } else if (expression3){    Statement(s) to be executed if expression 3 is true } else{    Statement(s) to be executed if no expression is true }ExampleYou can try to run the following to learn how to work with if…else if statement in ... Read More

What is if statement in JavaScript?

Nishtha Thakur
Updated on 13-Jun-2020 11:37:20

154 Views

The if statement is the fundamental control statement that allows JavaScript to make decisions and execute statements conditionally. SyntaxThe syntax for a basic if statement is as follows −if(expression){    Statement(s)to be executed if expression is true }Here a JavaScript expression is evaluated. If the resulting value is true, the given statement(s) are executed. If the expression is false, then no statement would be not executed. Most of the times, you will use comparison operators while making decisions.ExampleYou can try to run the following to learn how to work with if statement in JavaScript −Live Demo           ... Read More

What is 'new' Operator in JavaScript?

Smita Kapse
Updated on 13-Jun-2020 09:27:27

127 Views

The new keyword in JavaScript is the new operator. It creates an instance of a user-defined object type.SyntaxHere’s the syntax −new constructor[([arguments])]ExampleLet us see an example to learn about the usage of new operator −                          var dept = newObject();          dept.employee = "David";          dept.department = "Programming";          dept.technology = "C++";          document.getElementById("test").innerHTML =          dept.employee + "is working on " + dept.technology + " technology.";          

Advertisements