Finding sum of sequence upto a specified accuracy using JavaScript

AmitDiwan
Updated on 15-Mar-2026 23:19:00

239 Views

We need to find the sum of a sequence where each term is the reciprocal of factorials. The sequence is: 1/1, 1/2, 1/6, 1/24, ... where the nth term is 1/n!. Understanding the Sequence The sequence can be written as: 1st term: 1/1! = 1/1 = 1 2nd term: 1/2! = 1/2 = 0.5 3rd term: 1/3! = 1/6 ≈ 0.167 4th term: 1/4! = 1/24 ≈ 0.042 Each term is 1 divided by the factorial of its position number. Mathematical Formula Sum = 1/1! + 1/2! + 1/3! + ... + 1/n! Implementation const num = 5; const seriesSum = (n = 1) => { let sum = 0; let factorial = 1; for (let i = 1; i

What is a typical use case for JavaScript anonymous functions?

Mayank Agarwal
Updated on 15-Mar-2026 23:19:00

546 Views

In this article, we are going to explore the anonymous functions in JavaScript and their typical use cases. An anonymous function is a function without a name that can be stored in variables, passed as arguments, or used as return values. Anonymous functions are incredibly useful in JavaScript for callbacks, event handlers, functional programming methods like map(), filter(), and situations where you need a function only once. Syntax // Function expression let variable = function() { // code here }; // Arrow function (ES6) let variable = () => { ... Read More

How to disable uniform scaling on a canvas using FabricJS?

Rahul Gurung
Updated on 15-Mar-2026 23:19:00

379 Views

In this article, we are going to learn about how to disable uniform scaling in canvas using FabricJS. In FabricJS, an object gets transformed proportionally when dragged from the corners. However, we can disable this behavior by using the uniformScaling property. Syntax new fabric.Canvas(element: HTMLElement|String, { uniformScaling: Boolean }: Object) Parameters element − This parameter is the element itself which can be derived using document.getElementById() or the id of the element itself. The FabricJS canvas will be initialized ... Read More

Adding a Carousel to Your Site with Slick.js

Mukul Latiyan
Updated on 15-Mar-2026 23:19:00

1K+ Views

In this tutorial, we will demonstrate how to use Slick.js to create responsive carousels for your websites. We'll start with a basic image carousel and then explore various customization options to enhance its functionality. If you try to create a carousel without using any libraries, it will be quite time-consuming. To reduce the effort and add multiple types of carousels with different properties, you can use Slick.js. Slick.js is a widely used jQuery plugin that allows us to create responsive carousels with multiple attributes and different properties. Features of Slick.js There are multiple reasons why Slick.js ... Read More

How to center an Image object on current viewport of canvas using FabricJS?

Rahul Gurung
Updated on 15-Mar-2026 23:19:00

1K+ Views

In this tutorial, we are going to learn how to center an Image object on current viewport of canvas 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 center an Image object on the current viewport of canvas, we use the viewportCenter method. Syntax viewportCenter(): fabric.Object This method centers the object within the current viewport of the canvas both horizontally and vertically. It returns ... Read More

How to draw a hexagon with Polygon using FabricJS?

Rahul Gurung
Updated on 15-Mar-2026 23:19:00

568 Views

We can create a Polygon object by creating an instance of fabric.Polygon. A polygon object can be characterized by any closed shape consisting of a set of connected straight line segments. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. Syntax new fabric.Polygon( points: Array, options: Object ) Parameters points − This parameter accepts an Array which denotes the array of points that make up the polygon object. options (optional) − This parameter ... Read More

How to transform a JavaScript iterator into an array?

Mohit Panchasara
Updated on 15-Mar-2026 23:19:00

2K+ Views

In JavaScript, iterators are objects that implement the iterator protocol, allowing you to traverse through collections like Sets, Maps, or custom iterables. Unlike arrays, you cannot access iterator elements by index, so converting iterators to arrays is often necessary for easier manipulation. Here are three effective methods to transform JavaScript iterators into arrays. Using the for-of Loop The for-of loop iterates through each element of an iterator. Inside the loop, you can access elements and push them to an array using the push() method. Syntax for (let element of iterator) { ... Read More

Number prime test in JavaScript by creating a custom function?

AmitDiwan
Updated on 15-Mar-2026 23:19:00

233 Views

A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. In JavaScript, we can create a custom function to check if a number is prime. Basic Prime Number Function Here's a simple approach to check if a number is prime: function checkNumberIsPrime(number) { if (number

Algorithm for matrix multiplication in JavaScript

AmitDiwan
Updated on 15-Mar-2026 23:19:00

2K+ Views

Matrix multiplication is a fundamental operation in linear algebra where two matrices are multiplied to produce a third matrix. In JavaScript, we can implement this algorithm using nested loops to calculate the dot product of rows and columns. Matrix Multiplication Rules For matrix multiplication to be valid, the number of columns in the first matrix must equal the number of rows in the second matrix. If matrix A is m×n and matrix B is n×p, the result will be an m×p matrix. Matrix A (m×n) ... Read More

What is the "get" keyword before a function in a class - JavaScript?

AmitDiwan
Updated on 15-Mar-2026 23:19:00

520 Views

The get keyword in JavaScript creates a getter method that allows you to access a function like a property. When you call the getter, it executes the function and returns its value without using parentheses. Syntax class ClassName { get propertyName() { // return some value } } Basic Example Here's how to define and use a getter method: class Employee { constructor(name) { ... Read More

Advertisements