Javascript Articles

Page 507 of 534

How can I use goto statement in JavaScript?

Abhinanda Shri
Abhinanda Shri
Updated on 15-Mar-2026 3K+ Views

JavaScript does not have a native goto statement. While goto is a reserved keyword, it cannot be used in standard JavaScript code. However, you can achieve similar control flow using labels with break and continue statements. Why goto Doesn't Exist in JavaScript The goto statement was intentionally excluded from JavaScript to promote structured programming and avoid "spaghetti code" that makes programs difficult to understand and maintain. Alternative: Using Labels with break and continue JavaScript provides labeled statements that work with break and continue for controlled jumps: let a = 0; beginning: while (true) ...

Read More

How to break a loop in JavaScript?

Ankitha Reddy
Ankitha Reddy
Updated on 15-Mar-2026 463 Views

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 More

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

Jennifer Nicholas
Jennifer Nicholas
Updated on 15-Mar-2026 1K+ Views

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 More

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

Abhishek Kumar
Abhishek Kumar
Updated on 15-Mar-2026 319 Views

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 More

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

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 716 Views

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 More

What is Subtraction Operator (-) in JavaScript?

Abhishek
Abhishek
Updated on 15-Mar-2026 2K+ Views

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 More

What is Unary Negation Operator (-) in JavaScript?

Abhishek
Abhishek
Updated on 15-Mar-2026 560 Views

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 More

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

Krantik Chavan
Krantik Chavan
Updated on 15-Mar-2026 488 Views

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 More

What is Bitwise XOR Assignment Operator (^=) in JavaScript?

Abhinaya
Abhinaya
Updated on 15-Mar-2026 369 Views

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 More

What is the "double tilde" (~~) operator in JavaScript?

Nitya Raut
Nitya Raut
Updated on 15-Mar-2026 3K+ Views

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 More
Showing 5061–5070 of 5,340 articles
« Prev 1 505 506 507 508 509 534 Next »
Advertisements