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
How to get the opacity of Image object using FabricJS?
In this tutorial, we are going to learn how to get the opacity of Image using FabricJS. We can create an Image object by creating an instance of fabric.Image. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. In order to get the opacity of Image, we use the getObjectOpacity method. Syntax getObjectOpacity(): Number Parameters This method takes no parameters and returns the current opacity value as a Number between 0 and 1. Using the getObjectOpacity Method Let's ...
Read MoreDesign Smiley Face Eyes that follow Mouse Cursor using CSS and JS
Creating animated smiley faces with eyes that follow the mouse cursor is an engaging way to learn CSS pseudo-elements and JavaScript event handling. This effect combines CSS animations with JavaScript mouse tracking to create interactive cartoon faces. How It Works The animation works by calculating the angle between the mouse position and each eye's center. JavaScript uses Math.atan2() to determine the rotation angle, then applies a CSS transform to rotate the eyeballs toward the cursor. HTML Structure We create multiple face containers, each containing two eyes represented by divs: ...
Read MoreExplain non-boolean value coercion to a boolean one in JavaScript?
We will learn non-boolean value coercion to a Boolean one in JavaScript. For beginners, coercion word is new in JavaScript. So, let's clarify what coercion is. Coercion is converting the variable of one data type to another data type. As we all know, JavaScript is not a type-strict language. So, we don't need to define the types of the variable. Sometimes, JavaScript automatically coerces the variables and gives unpredictable results in the output. There are two types of coercion in JavaScript. One is implicit coercion, and another is explicit coercion. We will learn both coercion one by one ...
Read MoreHow to append new information and rethrowing errors in nested functions in JavaScript?
In JavaScript, appending new information to errors and rethrowing them in nested functions helps create more informative error messages while preserving the original error details. This technique is essential for debugging complex applications with multiple function layers. Understanding Error Rethrowing Error rethrowing allows us to catch an error, add contextual information, and throw it again to be handled at a higher level. This maintains the error chain while providing additional debugging context. Basic Error Rethrowing Here's how to rethrow an error with additional information: function innerFunction() { throw new Error("Original ...
Read MoreHow to convert list of elements in an array using jQuery?
We can use jQuery.makeArray() method or jQuery.each() method to convert a list of elements into an array using jQuery. The makeArray() method is the most convenient way to perform this task. This method is used to convert an object into a native array. Using jQuery makeArray() Method The $.makeArray() method in jQuery converts an array-like object into a JavaScript array. It takes a single argument and converts it to an array. Syntax $.makeArray(obj) Here obj is an object that we want to convert to an array. Example In this example we ...
Read MoreMap numbers to characters in JavaScript
When mapping numbers to characters in JavaScript, we need to convert digits to their corresponding alphabetical positions (1='a', 2='b', etc.). A number can be mapped in multiple ways by grouping digits differently. For example, the number 12145 can be interpreted as: 1, 2, 1, 4, 5 → a, b, a, d, e 12, 1, 4, 5 → l, a, d, e 12, 14, 5 → l, n, e However, combinations like 1, 2, 1, 45 are invalid because 45 exceeds the alphabet range (1-26). Solution Approach We use recursion to explore all valid digit ...
Read MoreMap multiple properties in array of objects to the same array JavaScript
When working with arrays of objects in JavaScript, you often need to extract multiple property values and combine them into a single flat array. This tutorial shows different approaches to map multiple properties from an array of objects. Problem Statement Given an array of objects like this: const arr = [ {a: 1, b: 2}, {a: 3, b: 4}, {a: 5, b: 6} ]; We need to extract all property values and create a flat array: const output = [1, 2, 3, 4, ...
Read MoreRemove number from array and shift the remaining ones JavaScript
In this problem statement, our task is to write a function to remove numbers from an array and shift the remaining elements using JavaScript. We'll explore multiple approaches including the filter method, for loops, and in-place modification to achieve this functionality. Understanding the Problem We need to create a function that removes all occurrences of a given number from an array and shifts the remaining items to fill the gaps. For example, given array [1, 2, 3, 4, 2, 5] and number 2, the result would be [1, 3, 4, 5] with all instances of 2 removed and ...
Read MorePair whose sum exists in the array in JavaScript
In this article we will see how to find pairs of items in an array whose sum equals another element present in the same array. We'll use JavaScript to implement an efficient algorithm for this problem. Understanding the Problem The problem is to find pairs of numbers (a, b) in an array where a + b = c, and c is also present in the array. For example, in array [1, 2, 3, 4, 5], the pair (1, 2) has sum 3, which exists in the array. Approach Using Hash Set We'll use a Set data ...
Read MoreDetermining a pangram string in JavaScript
A pangram is a string that contains every letter of the English alphabet at least once. Examples include "The quick brown fox jumps over the lazy dog" and "Pack my box with five dozen liquor jugs". We need to write a JavaScript function that determines whether a given string is a pangram. For this problem, we'll focus on the 26 letters of the English alphabet, ignoring case sensitivity. How It Works The algorithm creates an array of all 26 letters, then iterates through the input string. For each letter found in the string, it removes that letter ...
Read More