Javascript Articles

Page 508 of 534

What is Modulus Operator (%) in JavaScript?

Abhishek
Abhishek
Updated on 15-Mar-2026 1K+ 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
Anvi Jain
Updated on 15-Mar-2026 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
Abhishek
Updated on 15-Mar-2026 42K+ 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

What is unsigned Right Shift Operator (>>>) in JavaScript?

Nancy Den
Nancy Den
Updated on 15-Mar-2026 605 Views

The unsigned right shift operator (>>>) shifts the binary representation of a number to the right by a specified number of positions, filling the leftmost bits with zeros regardless of the original sign bit. Syntax result = number >>> positions How It Works Unlike the signed right shift (>>) which preserves the sign bit, the unsigned right shift always fills with zeros from the left. This treats the number as an unsigned 32-bit integer. Example with Positive Number var a = 14; var b = 2; // Shift ...

Read More

What is the difference between == and === in JavaScript?

Daniol Thomas
Daniol Thomas
Updated on 15-Mar-2026 1K+ Views

In JavaScript, == (double equals) performs loose equality comparison with type coercion, while === (triple equals) performs strict equality comparison without type conversion. Double Equals (==) - Loose Equality The == operator converts operands to the same type before comparing them. This can lead to unexpected results: console.log(4 == 4); // true console.log('4' == 4); // true - string converted to number console.log(4 == '4'); // true - number converted to string console.log(0 == false); // ...

Read More

How to load a JavaScript function using the variable name?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 2K+ Views

In JavaScript, there are several ways to load and execute functions using variable names. This technique is useful when you need to dynamically call functions or store function references in variables. Functions are blocks of reusable code that can be stored in variables and called later. JavaScript supports both named functions and anonymous functions, giving you flexibility in how you organize and execute your code. Anonymous Functions Anonymous functions are functions without a name. They must be assigned to a variable to be callable. This is the primary way to load a JavaScript function using a variable ...

Read More

How to use JavaScript to hide a DIV when the user clicks outside of it?

Rishi Raj
Rishi Raj
Updated on 15-Mar-2026 1K+ Views

To hide a DIV when the user clicks outside of it, you can listen for click events on the document and check if the clicked element is the target DIV or one of its children. This technique is commonly used for closing modals, dropdowns, and tooltips. Basic Implementation The simplest approach is to attach a click listener to the document and hide the DIV when the click target is not the DIV itself: #hideMe { ...

Read More

What is the difference between decodeURIComponent and decodeURI?

Vikyath Ram
Vikyath Ram
Updated on 15-Mar-2026 499 Views

JavaScript provides two methods for decoding URL-encoded strings: decodeURIComponent() and decodeURI(). Understanding their differences is crucial for proper URL handling in web applications. decodeURIComponent The decodeURIComponent() method decodes all encoded characters in a URI component, including reserved characters like =, &, and ?. Syntax decodeURIComponent(encodedURIComponent) Example Test decodeURIComponent function displayComponent() { ...

Read More

What is the difference between single and double quotes in JavaScript?

Kumar Varma
Kumar Varma
Updated on 15-Mar-2026 264 Views

In JavaScript, you can use either single quotes or double quotes to define strings. Both are functionally identical, but it's important to maintain consistency throughout your code. Syntax let singleQuoted = 'Hello World'; let doubleQuoted = "Hello World"; Basic Examples let message1 = "Hello, JavaScript!"; let message2 = 'Hello, JavaScript!'; console.log(message1); console.log(message2); console.log(message1 === message2); // Both are identical Hello, JavaScript! Hello, JavaScript! true Escaping Quotes When your string contains quotes, you need to escape them or use the opposite quote type: // Escaping ...

Read More

How to write a JavaScript function to get the difference between two numbers?

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 9K+ Views

Use Math.abs() inside a JavaScript function to get the difference between two numbers in JavaScript. The Math.abs() method returns the absolute value, ensuring you always get a positive difference regardless of which number is larger. Syntax function getDifference(num1, num2) { return Math.abs(num1 - num2); } Example: Using Math.abs() for Difference You can try to run the following code to get the difference of numbers: var num1, num2; ...

Read More
Showing 5071–5080 of 5,340 articles
« Prev 1 506 507 508 509 510 534 Next »
Advertisements