Articles on Trending Technologies

Technical articles with clear explanations and examples

How to divide an unknown integer into a given number of even parts using JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 465 Views

When dividing an integer into equal parts, you may need to distribute the remainder across some parts to ensure all values are used. This can be achieved using the modular operator and array manipulation. How It Works The algorithm divides the integer by the number of parts to get a base value. If there's a remainder, it distributes the extra values by adding 1 to some parts. Example function divideInteger(value, parts) { var baseValue; var remainder = value % parts; ...

Read More

Casting a string to snake case - JavaScript

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

Snake case is a naming convention where words are separated by underscores (_) and all letters are lowercase. For example, "Hello World" becomes "hello_world". This article demonstrates how to convert any string to snake case using JavaScript. Syntax function toSnakeCase(str) { return str.split(' ') .map(word => word.toLowerCase()) .join('_'); } Example Here's a complete example that converts a sentence to snake case: ...

Read More

How to deal with floating point number precision in JavaScript?

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

Floating point precision issues occur when JavaScript cannot exactly represent certain decimal numbers in binary format. Common problems include 0.1 + 0.2 = 0.30000000000000004. JavaScript provides several methods to handle these precision issues. The Floating Point Problem JavaScript uses IEEE 754 double-precision floating-point format, which can cause unexpected results: console.log(0.1 + 0.2); // 0.30000000000000004 console.log(0.1 + 0.2 === 0.3); // false ...

Read More

How to find the text visible on the button with JavaScript?

Abhishek
Abhishek
Updated on 15-Mar-2026 10K+ Views

In this tutorial, we will discuss different approaches to find the text visible on the button with JavaScript. The text on a button shows what will happen if you click the button. To extract the text on the button, JavaScript provides us with the following two properties. Using the innerHTML Property Using the innerText Property Let us discuss both of the above properties in detail. Using the innerHTML Property The innerHTML property not only allows us to get the text inside any tag but also allows us to set the text ...

Read More

What is the best JavaScript code to create an img element?

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 258 Views

Creating an image element in JavaScript can be done in several ways. The most common approach is using document.createElement() or the Image() constructor. Using document.createElement() The standard DOM method to create an image element: Create Image Element // Create image element var myImg = document.createElement('img'); myImg.src = 'https://via.placeholder.com/150x100'; ...

Read More

Enable rear camera with HTML5

Samual Sam
Samual Sam
Updated on 15-Mar-2026 395 Views

To enable the rear camera in HTML5, you need to access the device's camera sources and specify which camera to use. This is particularly useful on mobile devices that have both front and rear cameras. Getting Available Camera Sources First, use the MediaDevices.enumerateDevices() method to get all available media devices: Rear Camera Access Start Rear Camera async function getRearCamera() { ...

Read More

Usage of border-style property in CSS

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 101 Views

The border-style property in CSS defines the style of an element's border. It controls how the border appears visually, such as solid, dashed, dotted, or hidden. Syntax border-style: value; Common Border Style Values Value Description none No border (default) solid Solid single line dashed Dashed line dotted Dotted line double Double solid lines groove 3D grooved effect ridge 3D ridged effect inset 3D inset effect outset 3D outset effect Basic Example ...

Read More

Adding an element at the end of the array in Javascript

Lokesh Badavath
Lokesh Badavath
Updated on 15-Mar-2026 610 Views

In JavaScript, adding elements to the end of an array is a fundamental operation. The most common and efficient method is using the push() method, which modifies the original array by appending one or more elements. An array is a special variable that can hold multiple values in a single ordered collection. Arrays in JavaScript are dynamic, meaning you can add or remove elements after creation. What is an Array? An array is a collection of items stored at contiguous memory locations. Arrays allow random access to elements, making it faster to access elements by their position ...

Read More

Jasmine.js comparing arrays

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 1K+ Views

In Jasmine.js, arrays can be compared in two different ways depending on your testing needs: Reference equality - checking if two variables refer to the same array object in memory Content equality - checking if arrays contain the same elements, even if they are different objects Using toBe() for Reference Equality The toBe() matcher checks whether two arrays are the exact same object in memory. This is useful when you want to verify that two variables reference the same array instance. describe("Array Reference Equality", () => { ...

Read More

Can we share a method between JavaScript objects in an array?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 199 Views

Yes, we can share methods between JavaScript objects in an array using prototypes or by defining shared methods outside the objects. This approach promotes code reusability and memory efficiency. Using Prototype Methods The most common way to share methods is through prototype inheritance. When you define a method on a constructor's prototype, all instances share that method. Shared Methods in JavaScript body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { ...

Read More
Showing 17251–17260 of 61,297 articles
Advertisements