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 disable right-clicking on a website using JavaScript?
To disable right-clicking on a website using JavaScript, you can use the contextmenu event to cancel the default behavior of the right-click. The contextmenu event is a DOM event that is triggered when a user right-clicks on an element in a user interface. It is a type of mouse event, similar to the click event, but it is specific to right-clicks. In JavaScript, you can use the addEventListener method to attach a contextmenu event listener to an element. The event listener function will be called whenever the contextmenu event is triggered on the element. Here's an example ...
Read MoreSort array of objects by string property value - JavaScript
Sorting an array of objects by a string property is a common task in JavaScript. The most efficient approach uses the built-in sort() method with localeCompare() for proper alphabetical ordering. Sample Data Let's work with this array of person objects: const people = [ { first_name: 'Lazslo', last_name: 'Jamf' }, { first_name: 'Pig', last_name: 'Bodine' }, { first_name: 'Pirate', last_name: 'Prentice' } ]; console.log("Original array:", people); Original array: [ { first_name: 'Lazslo', last_name: 'Jamf' }, { ...
Read MoreJavaScript map() is not saving the new elements?
The map() method creates a new array with transformed elements but doesn't modify the original array. A common mistake is not assigning the returned value from map() to a variable. The Problem: Not Saving map() Results map() returns a new array, so you must capture its return value: let numbers = [1, 2, 3]; // Wrong: map() result is ignored numbers.map(x => x * 2); console.log(numbers); // Original array unchanged // Correct: assign the result let doubled = numbers.map(x => x * 2); console.log(doubled); // New array with transformed values [ ...
Read MoreHow to create a password generator - JavaScript?
These days, password generators can be found all over the internet. Without a strong enough password, websites frequently won't let you establish an account. In this article, we'll learn how to create a password generator using JavaScript and the Math.random() method. Let's dive into creating a password generator step by step. We'll use Math.random() to generate cryptographically secure random passwords with customizable length and character sets. Understanding Math.random() The JavaScript Math.random() function returns a floating-point pseudo-random number between 0 (inclusive) and 1 (exclusive). We can scale this random number to select characters from our password character set. ...
Read MoreFinding the longest word in a string in JavaScript
We are required to write a JavaScript function that takes in a string as the only argument. The function should then iterate through the string and find and return the longest word from the string. For example − If the input string is − const str = 'Coding in JavaScript is really fun'; Then the output string should be − const output = 'JavaScript'; Using Array.reduce() Method The most efficient approach uses the reduce() method to iterate through words and track the longest one: const str = ...
Read MoreCalculating and adding the parity bit to a binary using JavaScript
A parity bit, or check bit, is a bit added to a string of bits to ensure that the total number of 1-bits in the string is even or odd. This is commonly used in error detection and data transmission. Problem Statement We need to write a JavaScript function that takes two parameters: the desired parity (either 'even' or 'odd') and a binary string representation. The function should return the parity bit (0 or 1) that needs to be added to achieve the specified parity. How Parity Bits Work Even Parity Example: ...
Read MoreStream writable.writableLength Property in Node.js
The writable.writableLength property returns the number of bytes (or objects) in the queue waiting to be written. This property is useful for monitoring buffer status and understanding the backpressure in your writable streams. Syntax writable.writableLength How It Works The property counts data that is: Buffered in the internal queue Waiting to be processed by the _write() method Corked (temporarily held) in memory Data that has already been written or is currently being processed is not counted. Example 1: Basic Usage with Cork Create a file named writableLength.js and run ...
Read MoreHow to lock the flipping during scaling of Rectangle using FabricJS?
In this tutorial, we are going to learn how to lock the flipping during scaling of a Rectangle using FabricJS. Just as we can specify the position, colour, opacity and dimension of a rectangle object in the canvas, we can also specify whether we want to stop flipping an object during scaling. This can be done by using the lockScalingFlip property. Syntax new fabric.Rect({ lockScalingFlip : Boolean }: Object) Parameters Options (optional) − This parameter is an Object which provides additional customizations to our rectangle. Using this parameter, properties such as colour, cursor, ...
Read MoreHow to set the size of superscript with Text using FabricJS?
In this tutorial, we are going to learn how to set the size of superscript with Text using FabricJS. We can display text on canvas by adding an instance of fabric.Text. Not only does it allow us to move, scale and change the dimensions of the text but it also provides additional functionality like text alignment, text decoration, line height which can be obtained by the properties textAlign, underline and lineHeight respectively. We can also use the superscript property where we can specify its size. Syntax new fabric.Text(text: String , { superscript : {"size": Number, "baseline": Number}: ...
Read MoreHow to show images with a click in JavaScript using HTML?
To display images on click using JavaScript and HTML, you can create hidden images, add click events, and reveal images dynamically for an interactive user experience. This technique enhances user engagement and improves page load times by showing content only when needed. Users often want to create interactive web pages where images are initially hidden and can be revealed with a click. The challenge is implementing this functionality using JavaScript and HTML in a simple and efficient manner. Approaches to Show Images with a Click Using the Style Display Property Using ...
Read More