Articles on Trending Technologies

Technical articles with clear explanations and examples

What is the use of ()(parenthesis) brackets in accessing a function in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 574 Views

The parentheses () are crucial for function invocation in JavaScript. Accessing a function without parentheses returns the function reference, while using parentheses calls the function and returns its result. Function Reference vs Function Call When you write a function name without parentheses, JavaScript treats it as a reference to the function object. With parentheses, JavaScript executes the function. Without Parentheses - Function Reference Accessing a function without parentheses returns the function definition itself, not the result: function toCelsius(f) { return (5/9) * ...

Read More

Program to retrieve the text contents of the user selection using JavaScript.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 186 Views

In JavaScript, you can retrieve the text contents of a user's selection using the window.getSelection() method. This is useful for creating text highlighting features, copy functionality, or interactive reading applications. How It Works The window.getSelection() method returns a Selection object representing the range of text selected by the user. You can convert this to a string using the toString() method. Example Text Selection Demo body ...

Read More

How to create a function which returns only even numbers in JavaScript array?

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

Here, we need to write a function that takes one argument, which is an array of numbers, and returns an array that contains only the numbers from the input array that are even. So, let's name the function as returnEvenArray, the code for the function will be − Example const arr = [3, 5, 6, 7, 8, 4, 2, 1, 66, 77]; const returnEvenArray = (arr) => { return arr.filter(el => { return el % 2 === 0; }) }; ...

Read More

How to add properties from one object into another without overwriting in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 703 Views

When merging objects in JavaScript, you often want to add properties from one object to another without overwriting existing values. This preserves the original object's data while incorporating new properties. The Problem Consider these two objects where some properties overlap: var first = {key1: 100, key2: 40, key3: 70}; var second = {key2: 80, key3: 70, key4: 1000}; console.log("First object:", first); console.log("Second object:", second); First object: { key1: 100, key2: 40, key3: 70 } Second object: { key2: 80, key3: 70, key4: 1000 } We want to add key4 from ...

Read More

Sum similar numeric values within array of objects - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 960 Views

Suppose, we have an array of objects like this — const arr = [ {"firstName":"John", "value": 89}, {"firstName":"Peter", "value": 151}, {"firstName":"Anna", "value": 200}, {"firstName":"Peter", "value": 22}, {"firstName":"Anna", "value": 60} ]; We are required to write a JavaScript function that takes in one such array and combines the value property of all those objects that have similar value for the firstName property. Therefore, for the above array, the output should look like — const output = [ ...

Read More

How to get the number of forms in a document with JavaScript?

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

In this tutorial, we will learn how to get the number of forms in a document using JavaScript. Since different methods are used to create forms in an HTML document, it might get tricky to get the number of forms present. However, you can use some methods to count the forms created without the form tag. Using the length Property The most widely accepted method to create forms in HTML documents is using the tag. Some websites also use tags to create forms in the document. Hence, we will discuss the method to get the number ...

Read More

How to set the width of an element's border with JavaScript?

Sai Subramanyam
Sai Subramanyam
Updated on 15-Mar-2026 1K+ Views

To set the width of an element's border in JavaScript, use the borderWidth property. This property allows you to dynamically modify border thickness after the page loads. Syntax element.style.borderWidth = "value"; The value can be specified in pixels (px), keywords (thin, medium, thick), or other CSS units. Example: Changing Border Width #box { border: thick solid gray; ...

Read More

What is the most efficient way of assigning all my HTML5 video sources as trusted without having to loop over all of them

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

In AngularJS applications, you can efficiently trust all HTML5 video sources by configuring the $sceDelegateProvider in your app's config phase. This eliminates the need to loop through individual video elements. Understanding SCE (Strict Contextual Escaping) AngularJS uses SCE to prevent XSS attacks by restricting resource URLs. Video sources must be explicitly trusted or whitelisted to load properly. Global Video Source Whitelisting Configure trusted video sources globally in your application module: app.config(function($sceDelegateProvider) { $sceDelegateProvider.resourceUrlWhitelist([ // Allow same origin resource loads ...

Read More

Set the opacity of an image with CSS

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

To set the opacity of an image, you can use the CSS opacity property. This is the modern standard method that works across all browsers. The opacity property accepts values from 0 (completely transparent) to 1 (completely opaque). Syntax opacity: value; Where value is a number between 0 and 1: 0 = completely transparent (invisible) 0.5 = 50% transparent 1 = completely opaque (default) Example: Basic Image Opacity .opacity-demo { ...

Read More

How can Forgotten timers or callbacks cause memory leaks in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 786 Views

JavaScript memory leaks commonly occur when timers and callbacks maintain references to objects that should be garbage collected. Understanding these patterns helps prevent memory issues in web applications. How Timers Create Memory Leaks When objects are referenced inside timer callbacks, the garbage collector cannot release them until the timer completes. If timers run indefinitely or reset themselves, the referenced objects remain in memory permanently. Timer Functions Overview JavaScript provides two main timing functions: setTimeout() - Executes a function once after a specified delay setInterval() - Executes a function repeatedly at specified intervals ...

Read More
Showing 16871–16880 of 61,297 articles
Advertisements