Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
Get global variable dynamically by name string in JavaScript?
In JavaScript, you can access global variables dynamically using their name as a string through the window object (in browsers) or global object (in Node.js). Syntax // Browser environment window[variableName] // Node.js environment global[variableName] // Using globalThis (works in both) globalThis[variableName] Basic Example Dynamic Global Variables // Define global variables ...
Read MoreExplain 'Not a constructor function' error in JavaScript?
The "Not a constructor function" error occurs when we try to use the new keyword with a value that isn't a constructor function. This TypeError is thrown when JavaScript expects a constructor but receives a primitive value, object, or non-constructor function. What Causes This Error The error occurs when we attempt to instantiate something that cannot be used as a constructor: Primitive values (numbers, strings, booleans) Regular objects Arrow functions (in strict mode) Built-in methods that aren't constructors Example: Using Primitive as Constructor Constructor Error Demo ...
Read MoreHow to turn words into whole numbers JavaScript?
We need to write a function that takes a string of number words as input and converts them into their equivalent whole number. Problem Overview Given a string containing number words separated by spaces, we want to convert each word to its corresponding digit and combine them into a single number. "one five seven eight" -------> 1578 "two eight eight eight" -------> 2888 Approach The solution involves creating a mapping of number words to digits, then iterating through each word to build the final number. We split the input string by whitespace ...
Read MoreCounting the number of redundant characters in a string - JavaScript
We are required to write a JavaScript function that takes in a string and returns the count of redundant characters in the string. A redundant character is any character that appears more than once, where all duplicate occurrences (except the last one) are considered redundant. For example − If the string is − const str = 'abcde' Then the output should be 0 because each character appears only once. If the string is − const str = 'aaacbfsc'; Then the output should be 3 because 'a' appears 3 times (2 ...
Read MoreCheck if a string is sorted in JavaScript
We are required to write a JavaScript function that takes in a string and checks whether it is sorted or not. A string is considered sorted if its characters are arranged in either ascending or descending order. For example: isSorted('adefgjmxz') // true (ascending) isSorted('zxmfdba') // true (descending) isSorted('dsfdsfva') // false (mixed order) Method 1: Character by Character Comparison This approach compares adjacent characters and tracks whether the string is ascending or descending: const str = 'abdfhlmxz'; const findDiff = (a, b) => a.charCodeAt(0) - b.charCodeAt(0); ...
Read MoreHow to append an item into a JavaScript array?
To append an item to a JavaScript array, you can use several methods. The most common approach is the push() method, which adds elements to the end of an array. Using push() Method The push() method adds one or more elements to the end of an array and returns the new length: var arr = ["marketing", "technical", "finance", "sales"]; arr.push("HR"); ...
Read MoreWhat is function overloading in JavaScript?
JavaScript does not support function overloading like other programming languages such as Java or C++. When you define multiple functions with the same name, JavaScript keeps only the last defined function. What Happens with Same Function Names Let's see what happens when we define multiple functions with the same name: function funcONE(x, y) { return x * y; } function funcONE(z) { return z; } // Only the last function definition is kept console.log(funcONE(5)); // prints 5 console.log(funcONE(5, 6)); // prints ...
Read MoreHow to set the distance between lines in a text with JavaScript?
To set the distance between lines in text, use the lineHeight CSS property via JavaScript. This property controls the vertical spacing between lines of text within an element. Syntax element.style.lineHeight = value; The lineHeight value can be: Number: Multiplier of font size (e.g., "2" = 2x font size) Pixels: Fixed height (e.g., "30px") Percentage: Relative to font size (e.g., "150%") Example: Setting Line Height with Button Click Line Height Demo ...
Read MoreHow to take a snapshot of HTML5-JavaScript based video player?
You can capture a still frame from an HTML5 video player by drawing the current video frame onto a canvas element. This technique is useful for creating thumbnails, implementing pause screens, or saving video snapshots. How It Works The process involves using the drawImage() method to copy the current video frame to a canvas. The canvas acts as a snapshot buffer that can be manipulated or saved. Example Your ...
Read MoreTop frameworks for HTML5 based mobile development
The following are some of the top frameworks for HTML5 based mobile development, each offering unique advantages for creating cross-platform mobile applications: Kendo UI Kendo UI provides a comprehensive suite of HTML5 UI widgets and tools for building cross-platform mobile applications. It offers native-like performance and appearance across different devices and operating systems. // Basic Kendo UI Mobile App initialization var app = new kendo.mobile.Application(document.body, { transition: 'slide', layout: 'tabstrip-layout' }); Bootstrap Bootstrap is a responsive front-end framework that supports HTML, CSS, and JavaScript for ...
Read More