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
Javascript Articles
Page 216 of 534
How to clone a given regular expression in JavaScript?
JavaScript's regular expression support is widely considered to be among the best in the world, but there's one area where it's lacking: there's no built-in way to clone a regular expression. This can be a problem when you need to create a new regular expression that is similar to an existing one but with a few small changes. The problem is that regular expressions are objects, and when you assign one regex to another variable, both variables reference the same object in memory. The Problem with Direct Assignment let regex1 = /foo/g; let regex2 = regex1; ...
Read MoreHow to uncurry a function up to depth n in JavaScript?
In JavaScript, a function is considered "curried" if it takes one or more arguments and returns a new function that expects the remaining arguments. Currying is a powerful technique that can be used to create new functions from existing ones, or to "uncurry" a function up to depth n. Why do we uncurry a function? There are several reasons why you might want to uncurry a function. For example, you may want to − Use a curried function in a context where a non-curried function is expected Convert ...
Read MoreDifference between JavaScript and AngularJS
JavaScript is a scripting language that is used to generate dynamic HTML pages with interactive effects on a webpage that runs in the web browser of the client. On the other hand, Angular JS is a framework that is built on JavaScript and adds new functionalities to HTML. Its primary purpose is to facilitate the creation of dynamic and single-page web applications (SPAs). In this article, we are going to highlight the differences between Angular JS and JavaScript. Let's start with a basic understanding of JavaScript and AngularJS. What is JavaScript? JavaScript is a simple programming language ...
Read MoreHow to truncate an array in JavaScript?
This tutorial is going to be about truncating an array in JavaScript. Truncating an array means trimming some elements from the end and assigning back the new value of the truncated array to the actual array. Sometimes we need to truncate an array. For example, if there is an array with sorted elements in descending order, and we need only the first k sorted elements from the array. Instead of creating an extra array and modifying that, we can directly truncate the original array. There are several ways to truncate an array. Let's explore these methods. Syntax ...
Read MoreWhat are the different use cases of remainder operator (%) in JavaScript?
In this tutorial, we will explore the different use cases of the remainder operator (%). The % operator returns the remainder when one number is divided by another and takes the sign of the dividend (the first operand). What is Remainder? When dividing two numbers, if the dividend is not completely divisible by the divisor, there is always a remainder. The remainder is what's left over after the division. 10 ÷ 2 = 5 (remainder 0, completely divisible) 6 ÷ 4 = 1 (remainder 2, not completely divisible) The remainder operator works as: dividend ...
Read MoreHow to create a string by joining the elements of an array in JavaScript?
In this tutorial, we will see how to create a string by joining the elements of an array in JavaScript. We will explore two different approaches: using the addition operator (+) to manually concatenate elements, and using the built-in join() method, which is the recommended approach. Using the Addition Operator (+) In this approach, we manually loop through the array and concatenate each element with a separator using the addition operator. While this works, it's more verbose than using the built-in join() method. Algorithm STEP 1 − Create an array with ...
Read MoreHow to create an element from a string in JavaScript?
In this tutorial, we will explore various methods to create HTML elements from strings in JavaScript. Creating elements dynamically from strings is essential for building interactive websites, such as to-do list apps where items are added, deleted, and edited on the fly. Using createElement() Method The createElement() method is the standard way to create HTML elements dynamically in JavaScript. This method takes a string parameter representing the tag name and returns a new HTML element. Syntax document.createElement(tagName) Where tagName is a string representing the HTML tag (like "div", "p", "h1", "img"). The method ...
Read MoreHow to check if the value is primitive or not in JavaScript?
In JavaScript, data types are divided into two categories: primitive and non-primitive. Understanding how to check if a value is primitive is crucial for proper data handling. Primitive data types: String, number, undefined, boolean, null, symbol, and bigint. Non-primitive data types: Objects (including arrays, functions, and dates). Primitive values are immutable and represent data at the lowest level of the language. When you "change" a primitive value, you're actually creating a new value and reassigning it to the variable. Using Object() Constructor The Object() constructor converts primitive values to objects. By comparing the original value with ...
Read MoreHow to open a webcam using JavaScript?
In this tutorial, we will learn how to open a webcam using JavaScript. This can be accomplished using WebRTC (Web Real-Time Communication), which allows us to access and capture webcam and microphone devices on the user's system. Understanding getUserMedia() We can access the user's webcam and microphone using the navigator.mediaDevices.getUserMedia() method. This function requires user permission and returns a Promise that resolves when access is granted. Basic Implementation Steps Follow these steps to implement webcam access: STEP 1 − Create HTML elements including a video element for the webcam stream and a ...
Read MoreHow to add line height to multiline text in IText using FabricJS?
In this tutorial, we are going to learn about how to add line height to multiline text in IText object using FabricJS. The IText class was introduced in FabricJS version 1.4, extends fabric.Text and is used to create IText instances. An IText instance gives us the freedom to select, cut, paste or add new text without additional configurations. There are also various supported key combinations and mouse/touch combinations which make text interactive which are not provided in Text. Textbox, however, which is based on IText allows us to resize the text rectangle and wraps lines automatically. This is not ...
Read More