Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Web Development Articles
Page 525 of 801
How to break a loop in JavaScript?
The break statement is used to exit a loop immediately and continue executing the code after the loop. When a break is encountered, the loop terminates completely, unlike continue which only skips the current iteration. Syntax break; Breaking a for Loop The most common use of break is to exit a loop when a certain condition is met: var text = ""; ...
Read MoreWhat is the best way to break from nested loops in JavaScript?
The best way to break from nested loops in JavaScript is to use labels. A label is an identifier followed by a colon (:) that allows you to control loop flow more precisely with break and continue statements. Syntax labelName: for (let i = 0; i < n; i++) { for (let j = 0; j < m; j++) { if (condition) break labelName; // Breaks outer loop } } Example: Breaking from Nested Loops ...
Read MoreHow to use for...in statement to loop through an Array in JavaScript?
The for...in statement in JavaScript iterates over all enumerable properties of an object or array. While it can be used with arrays, it's primarily designed for objects since it iterates over property names (indices for arrays) rather than values. Syntax for (variable in object) { // code block to be executed } The loop variable receives the property names (or array indices), not the actual values. Using for...in with Arrays Here's how for...in works with arrays: for...in loop with Arrays ...
Read MoreWhat is the difference between break and continue statements in JavaScript?
JavaScript provides two important control statements for modifying loop execution: break and continue. While both affect loop flow, they serve different purposes. break Statement The break statement is used to exit a loop completely, terminating the entire loop execution and transferring control to the statement immediately following the loop. Example var x = 1; document.write("Entering the loop"); ...
Read MoreWhat is Subtraction Operator (-) in JavaScript?
The subtraction operator (-) is a binary arithmetic operator in JavaScript that subtracts the right operand from the left operand. It requires two operands and returns the mathematical difference between them. The subtraction operator follows standard mathematical rules - if the first operand is larger, the result is positive; if smaller, the result is negative. Syntax let result = operand1 - operand2; Basic Examples console.log(9 - 5); // 4 (positive result) console.log(5 - 9); // -4 (negative result) console.log(10 - 10); // 0 (zero result) ...
Read MoreWhat is Unary Negation Operator (-) in JavaScript?
The Unary Negation Operator (-) converts its operand to a number and then negates it. It operates on a single operand and returns the negative value. Boolean values are converted to 0 or 1 before negation, and numbers in different bases are converted to decimal first. Syntax -operand The unary negation operator (-) precedes the operand to negate its value. Basic Examples Let's see how the unary negation operator works with different data types: ...
Read MoreWhat is if...else if... statement in JavaScript?
The if...else if... statement allows JavaScript to evaluate multiple conditions sequentially and execute the first matching condition's code block. Syntax The syntax of an if...else if statement is as follows: if (condition1) { // Code to execute if condition1 is true } else if (condition2) { // Code to execute if condition2 is true } else if (condition3) { // Code to execute if condition3 is true } else { // Code to execute if no condition is true } How It ...
Read MoreWhat is Bitwise XOR Assignment Operator (^=) in JavaScript?
The Bitwise XOR Assignment Operator (^=) performs an XOR (exclusive OR) operation between the left and right operands, then assigns the result back to the left operand. It's a shorthand for a = a ^ b. Syntax variable ^= value; // Equivalent to: variable = variable ^ value; How XOR Works XOR returns 1 when bits are different, 0 when they're the same: let a = 2; // Binary: 10 let b = 3; // Binary: 11 console.log("Before: a =", a, "b =", b); a ^= b; ...
Read MoreWhat is the "double tilde" (~~) operator in JavaScript?
The "double tilde" (~~) operator is a double NOT bitwise operator in JavaScript. It converts a number to a 32-bit signed integer and truncates any decimal part, making it a faster alternative to Math.floor() for positive numbers. How It Works The tilde (~) operator performs bitwise NOT operation. When used twice (~~), it effectively converts a value to an integer by: Converting the value to a 32-bit signed integer Truncating decimal places (not rounding) Returning the integer result Example: Basic Usage ...
Read MoreWhat is Addition Operator (+) in JavaScript?
The addition operator (+) in JavaScript is used to add two numeric operands together. It performs mathematical addition and returns the sum of the values. Syntax result = operand1 + operand2; Example You can try to run the following code to work with the addition operator: var a = 33; var b = 10; ...
Read More