Articles on Trending Technologies

Technical articles with clear explanations and examples

Avoid Unexpected string concatenation in JavaScript?

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

JavaScript string concatenation can lead to unexpected results when mixing strings and numbers. Using template literals with backticks provides a cleaner, more predictable approach than traditional concatenation methods. The Problem with Traditional Concatenation When using the + operator, JavaScript may perform string concatenation instead of numeric addition: let name = "John"; let age = 25; let score = 10; // Unexpected string concatenation console.log("Age: " + age + score); // "Age: 2510" (not 35!) console.log(name + " is " + age + " years old"); Age: 2510 John is 25 years ...

Read More

Convert a list of string coords into two float lists of Lat/Longitude coordinates in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 660 Views

When working with coordinate data in JavaScript, you often need to parse string coordinates and separate them into latitude and longitude arrays. This is common when processing GPS data or API responses. Input Data Format Let's start with a list of coordinate strings in "latitude, longitude" format: var listOfStrings = ["10.45322, -6.8766363", "78.93664664, -9.74646646", "7888.7664664, -10.64664632"]; console.log("Input coordinates:"); console.log(listOfStrings); Input coordinates: [ '10.45322, -6.8766363', '78.93664664, -9.74646646', '7888.7664664, -10.64664632' ] Method 1: Using forEach with split() and map() This approach uses split() to separate coordinates and map(Number) to convert strings to ...

Read More

Find the Sum of fractions - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 743 Views

In JavaScript, we can calculate the sum of fractions by finding a common denominator and adding the numerators. This tutorial shows how to add fractions represented as arrays without converting to decimals. Problem Statement Given an array of arrays where each subarray contains two numbers representing a fraction, we need to find their sum in fraction form. const arr = [[12, 56], [3, 45], [23, 2], [2, 6], [2, 8]]; // Represents fractions: 12/56, 3/45, 23/2, 2/6, 2/8 Algorithm Overview To add fractions a/b + c/d, we use the formula: (a*d + c*b) ...

Read More

How to make an anchor tag refer to nothing?

varun
varun
Updated on 15-Mar-2026 5K+ Views

To make an anchor tag refer to nothing, use javascript:void(0). The following link does nothing because the expression "0" has no effect in JavaScript. Here the expression "0" is evaluated, but it is not loaded back into the current document. Using javascript:void(0) The javascript:void(0) approach prevents the default link behavior and returns undefined, making the link inactive. Inactive Anchor Tag Click the following, This won't react at all... Click me! Alternative Methods There are ...

Read More

How to get the value of the hreflang attribute of a link in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 1K+ Views

In this tutorial, we will learn how to get the value of the hreflang attribute of a link in JavaScript. The hreflang is an attribute of a link or anchor tag which specifies the language of the linked document or href attribute. It is used by search engines to understand the link's language and the targeted geographical location of the website. For better SEO hreflang attribute must be used. A single language or combination of language and region is used as the value of the hreflang attribute. It uses the language code ISO-639-1 and region code ISO-3166-1. ...

Read More

Set the right margin of an element with CSS

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

The margin-right property in CSS is used to set the right margin of an element. It creates space on the right side of an element, pushing it away from adjacent elements or the container's edge. Syntax margin-right: value; Values The margin-right property accepts several types of values: Length units: px, em, rem, pt, cm, etc. Percentage: Relative to the width of the containing element auto: Browser calculates the margin automatically inherit: Inherits from parent element Example with Different Values ...

Read More

How to use finally on promise with then and catch in Javascript?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 2K+ Views

JavaScript asynchronous programming uses promise objects that don't block execution but signal when operations complete. Promises can either resolve successfully or reject with an error. The finally() method executes cleanup code regardless of the promise outcome, similar to finally blocks in synchronous try-catch statements. Syntax promise .then(result => { // handle success }) .catch(error => { // handle error }) .finally(() => { // ...

Read More

How to test and execute a regular expression in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 339 Views

JavaScript provides two main methods for testing and executing regular expressions: test() and exec(). The test() method returns a boolean indicating if a pattern matches, while exec() returns detailed match information or null. Regular Expression Methods There are two primary ways to work with regular expressions in JavaScript: test() - Returns true/false if pattern matches exec() - Returns match details or null Example: Using test() and exec() Regular Expression Testing ...

Read More

Can we assign new property to an object using deconstruction in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 188 Views

You can assign new properties to an object using destructuring in JavaScript. This technique allows you to extract values from one object and assign them as properties to another object. Basic Syntax // Destructuring assignment to object properties ({ property1: targetObj.newProp1, property2: targetObj.newProp2 } = sourceObj); Example Object Destructuring Assignment body { ...

Read More

How to Sort object of objects by its key value JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 703 Views

Let's say, we have an object with keys as string literals and their values as objects as well like this − const companies = { 'landwaves ltd': {employees: 1200, worth: '1.2m', CEO: 'Rajiv Bansal'}, 'colin & co': {employees: 200, worth: '0.2m', CEO: 'Sukesh Maheshwari'}, 'motilal biscuits': {employees: 975, worth: '1m', CEO: 'Rahul Gupta'}, 'numbtree': {employees: 1500, worth: '1.5m', CEO: 'Jay Kumar'}, 'solace pvt ltd': {employees: 1800, worth: '1.65m', CEO: 'Arvind Sangal'}, 'ambicure': {employees: 170, worth: '0.1m', CEO: 'Preetam Chawla'}, ...

Read More
Showing 17401–17410 of 61,297 articles
Advertisements