What is Subtraction Operator (-) in JavaScript?

Abhishek
Updated on 15-Mar-2026 22:00:29

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
Updated on 15-Mar-2026 22:00:11

576 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
Updated on 15-Mar-2026 21:59:46

515 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
Updated on 15-Mar-2026 21:59:33

386 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
Updated on 15-Mar-2026 21:59:20

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

What is Addition Operator (+) in JavaScript?

Anvi Jain
Updated on 15-Mar-2026 21:59:05

361 Views

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

What is Addition Assignment Operator (+=) in JavaScript?

Nitya Raut
Updated on 15-Mar-2026 21:58:56

326 Views

The Addition Assignment Operator (+=) adds the right operand to the left operand and assigns the result back to the left operand. It's a shorthand way of writing a = a + b. Syntax variable += value; // Equivalent to: variable = variable + value; Example with Numbers Here's how the addition assignment operator works with numeric values: var a = 33; ... Read More

What is Modulus Operator (%) in JavaScript?

Abhishek
Updated on 15-Mar-2026 21:58:45

2K+ Views

The modulus operator (%) in JavaScript returns the remainder after dividing one number by another. It's also called the remainder operator and is commonly used in programming for tasks like checking if a number is even or odd. Syntax operand1 % operand2 Where operand1 is the dividend and operand2 is the divisor. The operation returns the remainder of the division. Basic Examples console.log(10 % 3); // 1 (10 ÷ 3 = 3 remainder 1) console.log(15 % 4); // 3 (15 ÷ 4 = 3 remainder 3) console.log(20 % 5); ... Read More

How to redirect website after certain amount of time without JavaScript?

Anvi Jain
Updated on 15-Mar-2026 21:58:27

6K+ Views

To redirect from an HTML page without JavaScript, use the META tag with the http-equiv="refresh" attribute. This provides an HTTP header that tells the browser to automatically redirect after a specified number of seconds. Through this method, you can automatically redirect your visitors to a new homepage or any other page. Set the content attribute to 0 if you want the redirect to happen immediately. Syntax Parameters The content attribute contains two parts separated by a semicolon: seconds - Number of seconds to wait before redirecting url - The destination ... Read More

How to use JavaScript to redirect a webpage after 5 seconds?

Abhishek
Updated on 15-Mar-2026 21:58:10

43K+ Views

In this tutorial, we learn to use JavaScript to redirect a webpage after 5 seconds. To redirect a webpage after a delay, we use the setTimeout() method combined with window.location.href to set the destination URL. JavaScript provides two timing methods for delayed execution: setTimeout() for single execution and setInterval() for repeated execution. For page redirection, setTimeout() is the preferred method. To redirect a page we use the window.location.href property to change the current page URL: window.location.href = "https://example.com"; Using setTimeout() Method (Recommended) The setTimeout() method executes a function once after a specified delay. ... Read More

Advertisements