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

Nancy Den
Updated on 15-Mar-2026 21:57:48

640 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
Updated on 15-Mar-2026 21:57:34

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

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
Updated on 15-Mar-2026 21:57:02

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
Updated on 15-Mar-2026 21:56:39

564 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
Updated on 15-Mar-2026 21:56:21

307 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
Updated on 15-Mar-2026 21:56:04

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

What does the operator || do in a var statement in JavaScript?

Shubham Vora
Updated on 15-Mar-2026 21:55:53

323 Views

In JavaScript, the logical OR operator (||) is commonly used in variable declarations to provide fallback or default values. When used with var, it returns the first "truthy" value or the last value if all are falsy. The logical OR operator evaluates operands from left to right and returns the first truthy value it encounters. If no truthy value is found, it returns the last operand. In JavaScript, falsy values include false, 0, "", null, undefined, and NaN. Syntax var result = expr1 || expr2; If expr1 is truthy, result will be expr1. Otherwise, ... Read More

How to extract the hostname portion of a URL in JavaScript?

Shubham Vora
Updated on 15-Mar-2026 21:55:26

12K+ Views

In this tutorial, we will see how to extract the hostname portion of a URL in JavaScript. What is a URL? A URL (Uniform Resource Locator) is a web address that identifies a specific resource on the internet. For example, tutorialspoint.com is a word-based URL. An IP address can also be used as a URL (ex. 192.168.2.24). Since names are simpler to recall than numbers, most users submit the name's address when searching on the internet. A URL is a method by which web browsers request specific pages from web servers. The syntax/format of a URL is ... Read More

Is it required to have a return a value from a JavaScript function?

George John
Updated on 15-Mar-2026 21:55:00

3K+ Views

In JavaScript, functions do not require a return statement. The return statement is optional, and functions can operate without explicitly returning a value. Functions Without Return Values When a function doesn't have a return statement, it automatically returns undefined: function greetUser(name) { console.log("Hello, " + name + "!"); // No return statement } let result = greetUser("Alice"); console.log("Function returned:", result); Hello, Alice! Function returned: undefined Functions With Return Values Functions can explicitly return values using the return statement: function ... Read More

Advertisements