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
Set the font family with CSS
The font-family property is used to change the face of a font. You can specify multiple font names as fallbacks, and the browser will use the first available font from the list. Syntax font-family: "font-name", fallback-font, generic-family; Example: Setting Font Family This text is rendered in either georgia, garamond, or the default serif font depending ...
Read MoreHow to concatenate two strings so that the second string must concatenate at the end of first string in JavaScript?
String concatenation is the process of joining two or more strings together to create a new string. In JavaScript, there are several methods to concatenate strings, with the second string being appended at the end of the first string. Using concat() Method The concat() method joins the calling string with the provided string arguments to create a new string. The original strings remain unchanged since strings in JavaScript are immutable. Syntax concat(str1) concat(str1, str2) concat(str1, str2, ... , strN) Parameters Parameter Description strN One or more strings to ...
Read MoreHow to find the accept-charset and enctype attribute of a form in JavaScript?
In HTML forms, the accept-charset and enctype attributes control character encoding and data transmission format. JavaScript provides properties to access these values programmatically. The accept-charset attribute specifies which character encodings the server accepts for form submission, while enctype defines how form data should be encoded when sent to the server. Using acceptCharset Property The acceptCharset property returns the value of the form's accept-charset attribute. Common values include "utf-8" (Unicode encoding) and "ISO-8859-1" (Latin alphabet encoding). Syntax document.getElementById('formID').acceptCharset; Example Here's how to retrieve the acceptable character set of a form: ...
Read MoreHow to implement asynchronous loop in JavaScript?
Asynchronous loops in JavaScript allow you to perform time-delayed or async operations within loops without blocking the main thread. This is essential when working with APIs, file operations, or timed delays. What is an Asynchronous Loop? A regular loop executes all iterations instantly. An asynchronous loop waits for each iteration to complete before moving to the next, using await with async functions. Using async/await with for Loop Asynchronous Loop ...
Read MoreFind longest string in array (excluding spaces) JavaScript
We are required to write a function that accepts an array of string literals and returns the index of the longest string in the array. While calculating the length of strings we don't have to consider the length occupied by whitespaces. If two or more strings have the same longest length, we have to return the index of the first string that does so. We will iterate over the array, split each element by whitespace, join again and calculate the length. We'll track the maximum length and its index, updating when we find a longer string. Syntax ...
Read MoreVowel, other characters and consonant difference in a string JavaScript
We are required to write a function that takes in a string of definite characters and the function should return the difference between the count of vowels plus other characters and consonants in the string. Problem Explanation For example, if the string is: "HEllo World!!" Then, we have 7 consonants, 3 vowels and 3 other characters here so the output should be: |7 - (3+3)| = 1 Hence, the output should be 1 Example const str = 'HEllo World!!'; const findDifference = str => { const creds ...
Read MoreSplit Space Delimited String and Trim Extra Commas and Spaces in JavaScript?
When working with strings that contain multiple commas and spaces, you can use regular expressions with split() and join() methods to clean them up effectively. The Problem Consider this messy string with multiple consecutive commas and spaces: var sentence = "My, , , , , , , Name, , , , is John ,, , Smith"; console.log("Original string:", sentence); Original string: My, , , , , , , Name, , , , is John ,, , Smith Solution: Using Regular Expression with split() and join() The split(/[\s, ]+/) method splits ...
Read MoreFinding difference of greatest and the smallest digit in a number - JavaScript
We are required to write a JavaScript function that takes in a number and returns the difference between the greatest and the smallest digit present in it. For example: If the number is 5464676, then the smallest digit here is 4 and the greatest is 7 Hence, our output should be 3 Example Let's write the code for this function — const num = 44353456; const difference = (num, min = Infinity, max = -Infinity) => { if(num){ const digit = num ...
Read MoreHow to get a string representation of a number in JavaScript?
Use the toString() method to get the string representation of a number. This method converts any number to its string equivalent and supports different number bases for advanced use cases. Syntax number.toString() number.toString(radix) Parameters radix (optional): An integer between 2 and 36 representing the base for numeric representation. Default is 10 (decimal). Basic Example var num1 = 25; ...
Read MoreWhat is the difference between "strict" and "non-strict" modes of JavaScript?
The "use strict" is a directive introduced in JavaScript 1.8.5 that enables strict mode execution. In strict mode, JavaScript enforces stricter parsing and error handling, while non-strict mode (the default) is more permissive and allows certain problematic practices. Enabling Strict Mode To enable strict mode, add "use strict"; at the beginning of your script or function. For global scope, place it at the top of the script file. Check the console for errors (F12) ...
Read More