Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
How to set the top position of an element with JavaScript?
In this tutorial, we shall learn to set the top position of an element with JavaScript. To set the top position of an element, we can use the DOM Style top property in JavaScript. Alternatively, we can use the DOM Style setProperty() method. Let us discuss our topic in brief. Using the Style top Property We can set or return the top position of an element using the JavaScript DOM style top property. Following is the syntax to set the top position of an element using the Style top property with the dot notation or square brackets. ...
Read MoreFat vs concise arrow functions in JavaScript
Arrow functions in JavaScript come in two forms: fat arrow (with curly braces) and concise arrow (without curly braces). The concise form is a streamlined syntax for single-expression functions that provides implicit return functionality. Syntax Comparison Fat arrow function with explicit return: let add = (a, b) => { return a + b; } Concise arrow function with implicit return: let add = (a, b) => a + b; Single parameter (parentheses optional): let square = x => x * x; No parameters (parentheses required): ...
Read MoreSmallest positive value that cannot be represented as sum of subarray JavaScript
We have a sorted array of positive integers like this: const arr = [1, 3, 6, 10, 11, 15]; We are required to write a function, say findSmallest() that takes in one such array and returns the smallest positive integer that cannot be represented as the sum of some subarray of this original array. For example, for the array written above, 2 is the smallest positive integer which cannot be reached by summing any subarray of this original array. Algorithm Approach Since the array is sorted, we can achieve the solution to this ...
Read MoreIteration of for loop inside object in JavaScript to fetch records with odd CustomerId?
In JavaScript, you can iterate through an array of objects using a for loop and filter records based on specific conditions. Here's how to fetch records with odd CustomerId values. Array of Objects Structure Let's start with an array containing customer objects: var customerDetails = [ { customerId: 101, customerName: "John" }, { customerId: 102, ...
Read MoreInserting element at falsy index in an array - JavaScript
We are required to write an Array function, let's say, pushAtFalsy() The function should take in an array and an element. It should insert the element at the first falsy index it finds in the array. If there are no empty spaces, the element should be inserted at the last of the array. We will first search for the index of empty position and then replace the value there with the value we are provided with. Understanding Falsy Values In JavaScript, falsy values include: null, undefined, false, 0, "" (empty string), and NaN. However, since 0 ...
Read MoreHow to set the bottom padding of an element with JavaScript?
To set the bottom padding of an element in JavaScript, use the paddingBottom property of the element's style object. This property allows you to dynamically modify the spacing between an element's content and its bottom border. Syntax element.style.paddingBottom = "value"; Where value can be specified in pixels (px), percentages (%), em units, or other valid CSS length units. Example Here's how to set the bottom padding of an element dynamically: #box { ...
Read MoreDifference between MessageChannel and WebSockets in HTML5
WebSockets and MessageChannel are both HTML5 communication technologies, but they serve different purposes. WebSockets enable real-time communication between browser and server, while MessageChannel facilitates secure communication between different browsing contexts within the same application. WebSockets Overview WebSockets provide bidirectional communication between browser and server over a single persistent connection. They're ideal for real-time applications like chat systems, live updates, and gaming. // WebSocket connection to server const socket = new WebSocket('wss://example.com/socket'); socket.onopen = function(event) { console.log('WebSocket connected'); socket.send('Hello Server!'); }; socket.onmessage = function(event) { ...
Read MoreAdd or subtract space between the letters that make up a word with CSS
To add or subtract space between the letters that make up a word, use the letter-spacing CSS property. This property controls the horizontal spacing between characters in text. Syntax letter-spacing: normal | length | initial | inherit; Property Values normal - Default spacing between letters length - Specific spacing value (px, em, rem, etc.) initial - Sets to default value inherit - Inherits from parent element Example: Adding Letter Spacing ...
Read MorePseudo mandatory parameters in JavaScript
Pseudo mandatory parameters in JavaScript allow you to enforce that certain function parameters must be provided by the caller. While JavaScript doesn't have built-in mandatory parameters like some other languages, you can simulate this behavior using various techniques. What are Pseudo Mandatory Parameters? Pseudo mandatory parameters are function parameters that appear optional syntactically but will throw an error if not provided. This helps catch bugs early and makes your function's requirements explicit. Method 1: Using a Helper Function The most common approach is to create a helper function that throws an error when called: ...
Read MoreRemove all characters of first string from second JavaScript
When working with strings in JavaScript, you may need to remove all characters from one string that appear in another string. This is useful for filtering, data cleaning, or text processing tasks. Let's say we have two strings with characters in no specific order. We need to write a function that takes these two strings and returns a modified version of the second string with all characters from the first string removed. Example Strings const first = "hello world"; const second = "hey there"; Using Array Methods (Recommended) The most straightforward approach uses ...
Read More