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
What is the role of screenX Mouse Event in JavaScript?
The screenX mouse event property returns the horizontal coordinate of the mouse pointer relative to the user's screen when an event is triggered. This is useful for tracking precise mouse positions across the entire screen. Syntax event.screenX Return Value Returns a number representing the horizontal distance in pixels from the left edge of the user's screen to the mouse pointer position. Example Click anywhere on the paragraph below to see the mouse coordinates displayed: ...
Read MoreDoes HTML5 Canvas support Double Buffering?
HTML5 Canvas doesn't have built-in double buffering, but you can implement it manually by creating a second off-screen canvas. This technique prevents flickering during complex animations by drawing to a hidden canvas first, then copying the complete frame to the visible canvas. What is Double Buffering? Double buffering uses two canvases: a visible "front buffer" and an invisible "back buffer". You draw your entire frame on the back buffer, then copy it to the front buffer in one operation. This eliminates the visual artifacts that occur when drawing directly to the visible canvas. Implementation Create an ...
Read MoreHow to use named arguments in JavaScript functions?
In this article, we will learn how to use named arguments in JavaScript, and how we can use it to significantly enhance code readability and maintainability. JavaScript allows us to simulate named arguments, which eliminate the need for the order of parameters to matter during function execution. We can then access the arguments by name inside the function definitions. Let's look at some of the examples and methods to understand the concept better: What are Named Arguments? Named arguments allow you to pass parameters to a function by explicitly specifying the parameter name rather than relying ...
Read MoreJavaScript (+) sign concatenates instead of giving sum?
The + sign concatenates strings instead of adding numbers when JavaScript treats the values as strings. This commonly happens with form inputs, which always return string values even when they contain numbers. The Problem: String Concatenation vs Addition When you use the + operator with strings, JavaScript concatenates them instead of performing mathematical addition: String Concatenation Problem // These are strings, not numbers var a = ...
Read MoreMapping the letter of a string to an object of arrays - JavaScript
Given a string, we are required to write a function that creates an object that stores the indexes of each letter in an array. The letters (elements) of the string must be the keys of object. The indexes should be stored in an array and those arrays are values. For example, if the input string is: const str = 'cannot'; Then the output should be: const output = { 'c': [0], 'a': [1], 'n': [2, 3], ...
Read MoreCan you take a screenshot of the page using HTML5 Canvas?
Html2Canvas is a JavaScript library that can take screenshots of web pages or specific elements. It doesn't capture actual screenshots but recreates the visual representation based on DOM information and CSS styles. How Html2Canvas Works The library reads the DOM structure and CSS properties to generate a canvas representation of the page. This approach works entirely in the browser without requiring server-side processing or special permissions. Basic Example Here's a complete example showing how to capture a screenshot of a specific container: ...
Read MoreCreating a Graph in Javascript
We'll be creating a graph class that supports weights and both directed and undirected types. This will be implemented using an adjacency list. As we move to more advanced concepts, both weights and directed nature of the graphs will come in handy. An adjacency list is an array A of separate lists. Each element of the array Ai is a list, which contains all the vertices that are adjacent to vertex i. We're defining it using 2 members, nodes and edges. Graph Class Structure Let's set up the graph class by defining our class and some methods ...
Read MoreTag names of body element's children in JavaScript?
In JavaScript, you can access the tag names of child elements within the body using the children property or the querySelector method. The children property returns an HTMLCollection of all child elements, while querySelector allows you to target specific elements using CSS selectors. Using the children property to get all child elements Using the querySelector method to select specific child elements Both approaches provide different ways to access and manipulate child elements within the DOM structure. Using the children Property The DOM children property returns an HTMLCollection of all child ...
Read MoreFunction to create diamond shape given a value in JavaScript?
In JavaScript, you can create a function to generate diamond-shaped patterns using stars and spaces. A diamond shape consists of two parts: an upper triangle that expands and a lower triangle that contracts. Example function createDiamondShape(size) { // Upper part of diamond (including middle) for (var i = 1; i = i; s--) { process.stdout.write(" "); } // Print stars for (var j = 1; j
Read MoreTrying to get number for each character in string - JavaScript
We are required to write a JavaScript function that takes in a string. It should print out each number for every corresponding letter in the string. For example, a = 1 b = 2 c = 3 d = 4 e = 5 . . . Y = 25 Z = 26 Therefore, if the input is "hello man", Then the output should be a number for each character − "8, 5, 12, 12, 15, 13, 1, 14" How It Works The solution uses the charCodeAt() method to get ...
Read More