Articles on Trending Technologies

Technical articles with clear explanations and examples

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 519 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 285 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

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

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 308 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
Shubham Vora
Updated on 15-Mar-2026 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
George John
Updated on 15-Mar-2026 2K+ 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

What is a standard for commenting a function in JavaScript?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 8K+ Views

JavaScript is used everywhere, from creating the back end using environments like Node.js to creating the front end using React.js, Vue.js, etc. In JavaScript, functions are fundamental building blocks used for operations, callbacks, constructors, and many other purposes. With extensive function usage, code can become messy and hard to debug. It becomes difficult to track which functions trigger which events, making proper commenting essential for maintainability. Writing effective function comments requires following standards that other developers can easily understand and work with. Standards for Commenting Functions in JavaScript Following are essential standards for commenting functions: ...

Read More
Showing 19071–19080 of 61,297 articles
Advertisements