Articles on Trending Technologies

Technical articles with clear explanations and examples

In JavaScript inheritance how to differentiate Object.create vs new?

Abhinanda Shri
Abhinanda Shri
Updated on 15-Mar-2026 230 Views

In JavaScript inheritance, Object.create() and new serve different purposes when setting up prototype chains. Understanding their differences is crucial for proper inheritance implementation. Object.create() - Prototype Only Inheritance When using Object.create(), you inherit only the prototype methods without executing the parent constructor: function BaseClass(name) { this.name = name; console.log("BaseClass constructor called"); } BaseClass.prototype.greet = function() { return "Hello from " + this.name; }; function ChildClass(name) { this.name = name; } // Using Object.create - inherits prototype only ...

Read More

toDataURL throw Uncaught Security exception in HTML

Samual Sam
Samual Sam
Updated on 15-Mar-2026 205 Views

The toDataURL() method throws an "Uncaught Security Exception" when trying to convert images from external domains to base64. This happens due to CORS (Cross-Origin Resource Sharing) restrictions that prevent accessing pixel data from cross-origin images. The Problem When you load an image from a different domain and try to use toDataURL(), the browser blocks access to prevent potential security vulnerabilities: function getBase64() { var img = document.getElementById("myImage"); var canvas = document.createElement("canvas"); var ctx = canvas.getContext("2d"); ...

Read More

What is the difference between 'throw new Error' and 'throw someObject' in javascript?

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 607 Views

In JavaScript, both throw new Error and throw someObject can be used to throw exceptions, but they differ in structure and best practices. Using throw new Error When you use throw new Error(), JavaScript creates a proper Error object with standard properties: try { throw new Error("Something went wrong"); } catch (error) { console.log("Name:", error.name); console.log("Message:", error.message); console.log("Stack:", error.stack ? "Available" : "Not available"); } Name: Error Message: Something went wrong Stack: Available Using throw ...

Read More

How to create a top navigation menu for smartphones / tablets with CSS and JavaScript?

Aman Kumar
Aman Kumar
Updated on 15-Mar-2026 769 Views

In this article, we are going to discuss how to create a responsive top navigation menu for smartphones and tablets using CSS and JavaScript. A navigation bar is usually the first pit-stop for users visiting a website who seek guidance to navigate through the site. It contains links to different sections of your website, providing easy access to important pages. Creating a mobile-friendly navigation menu involves using CSS media queries to hide navigation links on small screens and display a hamburger menu icon instead. When clicked, this icon toggles the visibility of the navigation links. How It ...

Read More

JavaScript Prompt Example

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 898 Views

In this article, we will learn to use the prompt() function in Javascript. The prompt() method in JavaScript allows developers to collect user input through a pop-up dialog box. What is the prompt() Method in JavaScript? The prompt dialog box is very useful when you want to pop-up a text box to get user input. Thus, it enables you to interact with the user. The user needs to fill in the field and then click OK. This dialog box is displayed using a method called prompt(). Syntax var userInput = prompt("Message", "Default value"); ...

Read More

JavaScript - Get the text of a span element

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 4K+ Views

In JavaScript, you can get the text content of a span element using several methods. The most common approaches are innerHTML, textContent, and innerText. Methods to Get Span Text There are three main properties to retrieve text from a span element: innerHTML - Gets HTML content including tags textContent - Gets plain text content (recommended) innerText - Gets visible text content Example: Getting Span Text Get Span Text ...

Read More

Why does Array.map(Number) convert empty spaces to zeros? JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 465 Views

When using Array.map(Number) on a string containing spaces, JavaScript converts empty spaces to zeros. This happens due to how the Number() constructor handles string-to-number conversion. The Problem Let's examine this behavior with a practical example: const digify = (str) => { const parsedStr = [...str].map(Number) return parsedStr; } console.log(digify("778 858 7577")); [ 7, 7, 8, 0, 8, 5, 8, 0, 7, 5, 7, 7 ] Notice how the spaces in the string are converted to 0 instead ...

Read More

Remove characters from a string contained in another string with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 430 Views

When working with strings in JavaScript, you might need to remove all characters from one string that appear in another string. This can be achieved using the replace() method combined with reduce(). Problem Statement Given two strings, we want to remove all characters from the first string that exist in the second string: var originalName = "JOHNDOE"; var removalName = "JOHN"; // Expected result: "DOE" Solution Using replace() and reduce() The reduce() method iterates through each character in the removal string, and replace() removes the first occurrence of that character from the original ...

Read More

Largest and smallest word in a string - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

We need to write a JavaScript function that takes a string and returns an array containing the smallest and largest words from the string based on their length. For example, if we have the string: const str = "Hardships often prepare ordinary people for an extraordinary destiny"; The output should be: const output = ["an", "extraordinary"]; The word "an" has 2 characters (smallest) and "extraordinary" has 13 characters (largest). Example Here's the complete implementation: const str = "Hardships often prepare ordinary people for an extraordinary destiny"; ...

Read More

How to convert a Boolean to Integer in JavaScript?

Ayyan
Ayyan
Updated on 15-Mar-2026 478 Views

In JavaScript, you can convert a Boolean to an integer using several methods. The most common approaches are the ternary operator, the Number() constructor, and the unary plus operator. Method 1: Using the Ternary Operator The ternary operator provides explicit control over the conversion values: Boolean to Integer Conversion var answer = true; ...

Read More
Showing 16801–16810 of 61,297 articles
Advertisements