Articles on Trending Technologies

Technical articles with clear explanations and examples

Shift certain array elements to front of array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 275 Views

We are required to write a JavaScript function that takes in an array of numbers. The function should bring all the 3-digit integers to the front of the array. Let's say the following is our array of numbers: const numList = [1, 324, 34, 3434, 304, 2929, 23, 444]; Understanding 3-Digit Numbers A 3-digit number is any integer between 100 and 999 (inclusive). We can check this using a simple condition: const isThreeDigit = num => num > 99 && num < 1000; console.log(isThreeDigit(324)); // true console.log(isThreeDigit(34)); // ...

Read More

How to get the tangent of a number in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 567 Views

In this tutorial, we will learn how to get the tangent of a number in JavaScript. The tangent of an angle is defined by the ratio of the length of the opposite side to the length of the adjacent side. It can also be defined as the ratio of sine and cosine function of an acute angle where the value of cosine function should not be zero. Mathematically: tan θ = opposite side / adjacent side also, tan θ = sin θ / cos θ Where θ = angle in radians The tangent of a ...

Read More

What are different Navigator methods available?

Jennifer Nicholas
Jennifer Nicholas
Updated on 15-Mar-2026 277 Views

The Navigator object provides several methods to interact with the browser and detect client capabilities. Here are the main Navigator methods available in JavaScript: Navigator Methods Overview Method Description Browser Support ...

Read More

AVL Rotations in Javascript

Sai Subramanyam
Sai Subramanyam
Updated on 15-Mar-2026 497 Views

To balance itself, an AVL tree may perform the following four kinds of rotations: Left rotation Right rotation Left-Right rotation Right-Left rotation The first two rotations are single rotations and the next two rotations are double rotations. To have an unbalanced tree, we at least need a tree of height 2. With this simple tree, let's understand them one by one. Left Rotation If a tree becomes unbalanced when a node is inserted into the right subtree of ...

Read More

Replace a value if null or undefined in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

In JavaScript, you can replace null or undefined values using the logical OR operator (||) or the nullish coalescing operator (??). Syntax // Using logical OR operator var result = value || defaultValue; // Using nullish coalescing operator (ES2020+) var result = value ?? defaultValue; Using Logical OR Operator (||) The || operator returns the first truthy value or the last value if all are falsy: var value = null; console.log("The original value:", value); var actualValue = value || "This is the Correct Value"; console.log("The replaced value:", actualValue); // ...

Read More

Square every digit of a number - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 490 Views

We are required to write a JavaScript function that takes in a number and returns a new number in which all the digits of the original number are squared and concatenated. For example: If the number is − 9119 Then the output should be − 811181 because 9² is 81 and 1² is 1. Example Following is the code − const num = 9119; const squared = num => { const numStr = String(num); let res = ''; ...

Read More

How to compare two JavaScript Date Objects?

Ramu Prasad
Ramu Prasad
Updated on 15-Mar-2026 422 Views

JavaScript Date objects can be compared directly using comparison operators (>, =, date2) { document.write("Current date is more recent."); } else { document.write("Custom date is more recent."); } Current date: Mon May 28 2018 09:48:49 GMT+0530 (India Standard Time) Custom date: Thu Dec 10 2015 20:15:10 GMT+0530 (India Standard Time) Current date is more recent. Comparing for ...

Read More

What is the role of clearTimeout() function in JavaScript?

Srinivas Gorla
Srinivas Gorla
Updated on 15-Mar-2026 347 Views

The clearTimeout() function cancels a timeout that was previously set with setTimeout(). When you call setTimeout(), it returns a timeout ID that you can use with clearTimeout() to stop the scheduled execution. Syntax clearTimeout(timeoutID) Parameters timeoutID - The identifier returned by setTimeout() that you want to cancel Basic Example clearTimeout Example Start Timer Cancel Timer ...

Read More

What will happen when [50,100] is converted to Number in JavaScript?

Sai Subramanyam
Sai Subramanyam
Updated on 15-Mar-2026 174 Views

Use the Number() method in JavaScript to convert to Number. When an array like [50, 100] is converted to Number in JavaScript, the result might be surprising. What Happens with Array to Number Conversion? When Number() is called on an array, JavaScript first converts the array to a string, then attempts to convert that string to a number. For arrays with multiple elements, this results in NaN (Not a Number). Example Convert [50, 100] to Number ...

Read More

Is HTML5 canvas and image on polygon possible?

George John
George John
Updated on 15-Mar-2026 483 Views

Yes, it is possible to draw images on polygons in HTML5 canvas. You can achieve this by creating a pattern from an image and applying it as a fill, or by using transformation matrices to manipulate how the image is drawn within the polygon shape. Method 1: Using Image Patterns Create a pattern using the image object and set it as the fillStyle for your polygon: const canvas = document.getElementById('myCanvas'); const context = canvas.getContext("2d"); // Create an image object const img = new Image(); img.onload = function() { ...

Read More
Showing 18261–18270 of 61,297 articles
Advertisements