In this tutorial, we are going to learn how to set the position of a Textbox from the left using FabricJS. We can customize, stretch or move around the text written in a textbox. In order to create a textbox, we will have to create an instance of fabric.Textbox class and add it to the canvas. The position from left can be changed by using the left property. Syntax new fabric.Textbox(text: String, { left: Number }: Object) Parameters text − This parameter accepts a String which is the text ... Read More
In this tutorial, we are going to learn how to scale an Image object to a given width 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 scale an Image object to a given width, we use the scaleToWidth method. Syntax scaleToWidth(value: Number, absolute: Boolean): fabric.Object Parameters value − This parameter accepts a Number which determines ... Read More
The JavaScript script tag is occasionally not understood by older browsers. If not, they will simply disregard it and display your script as though it were a section of the (X)HTML document's body. It's a smart option to use comments to hide scripts from outdated browsers to prevent it from happening. JavaScript is now supported by all modern browsers; however, earlier browsers did not. In this article, we'll learn how to prevent JavaScript code from executing in older browsers. As some of your viewers will be seeing the site on a phone while others are using a large ... Read More
In JavaScript, matching specific words using regex (regular expressions) is a common task for string pattern matching. This article covers the main methods to match words: test(), match(), and matchAll(). Understanding Word Boundaries The \b assertion represents a word boundary, ensuring you match complete words rather than partial matches within other words. Word Boundary Example const sentence = "mickey is holding mic."; const regex = /\bmic\b/; ... Read More
We are required to write a JavaScript function that takes in two numbers say m and n. Then function should calculate and return m^n. For example − For m = 4, n = 3, then power(4, 3) = 4^3 = 4 * 4 * 4 = 64 power(6, 3) = 216 Using Built-in Math.pow() Method JavaScript provides the built-in Math.pow() method for calculating powers: console.log(Math.pow(4, 3)); // 4^3 console.log(Math.pow(6, 3)); // 6^3 console.log(Math.pow(2, -2)); // 2^(-2) = 1/4 64 216 0.25 Custom Implementation Using Recursion ... Read More
In JavaScript, mapping values to keys means creating associations between identifiers (keys) and their corresponding data (values). This is commonly achieved using objects, which store data in key-value pairs for efficient retrieval. Understanding the Problem Objects in JavaScript are data structures that store information as key-value pairs. Keys serve as identifiers to access their associated values. There are several ways to access these values, with dot notation and bracket notation being the most common approaches. For example, with an object const obj = {name: 'John', age: 30}, you can access the name using obj.name or obj['name']. ... Read More
In this problem, we need to find the largest difference between elements with a twist using JavaScript. The twist is that we can only calculate the difference between an element and any smaller element that appeared before it in the array. Understanding the Problem Unlike finding the simple maximum difference between any two elements, this problem requires us to: Maintain the original array order (no sorting) Only consider differences where the larger element comes after the smaller one Find the maximum possible difference under these constraints ... Read More
We are required to write a JavaScript function that takes in an array of integers as the first argument and a number, say n, as the second argument. The function should check whether there exists two such numbers in the array that one is the nth multiple of the other. If there exists any such pair in the array, the function should return true, false otherwise. For example, if we have an array containing numbers 2 and 8, and n = 4, then 8 is the 4th multiple of 2 (8 = 2 × 4), so the ... Read More
We are required to write a JavaScript function that takes in an array of unique integers, arr, as the first argument, and target sum as the second argument. Our function should count the number of all pairs (with repetition allowed) that can add up to the target sum and return that count. Problem Example For example, if the input to the function is: const arr = [1, 2, 3]; const target = 4; Then the output should be: 7 Output Explanation The possible combination ways are: ... Read More
We are required to write a JavaScript function that takes in a decimal number, converts it into binary and reverses its bits (1 to 0 and 0 to 1) and returns the decimal equivalent of the new binary thus formed. Problem Given a decimal number, we need to: Convert the decimal number to binary Flip each bit (0 becomes 1, 1 becomes 0) Convert the resulting binary back to decimal Example Let's implement the function to reverse bits and convert back to decimal: ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance