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
Display the dropdown's (select) selected value on console in JavaScript?
In JavaScript, you can capture the selected value from a dropdown (select element) and display it in the console using the onchange event and console.log(). HTML Structure Here's a basic dropdown with an onchange event handler: Javascript MySQL MongoDB Java Complete Example Dropdown Selected Value Select a Subject: ...
Read MoreChecking progressive array - JavaScript
We are required to write a JavaScript function that takes in an array of strings, ordered by ascending length. The function should return true if, for each pair of consecutive strings, the second string can be formed from the first by adding a single letter either at the beginning or end. For example: If the array is given by − const arr = ["c", "ca", "can", "acan", "acane", "dacane"]; Then our function should return true. How It Works The algorithm checks each consecutive pair of strings to verify that the longer string ...
Read MoreSorting an array object by property having falsy value - JavaScript
Suppose, we have an array of objects like this − const array = [ {key: 'a', value: false}, {key: 'a', value: 100}, {key: 'a', value: null}, {key: 'a', value: 23} ]; We are required to write a JavaScript function that takes in one such array and places all the objects that have falsy values for the "value" property to the bottom and sorts all other objects in decreasing order by the "value" property. Understanding Falsy Values In JavaScript, falsy values include false, null, undefined, 0, "", ...
Read MoreHow to define integer constants in JavaScript?
ECMAScript allows usage of const to define constants in JavaScript. To define integer constants in JavaScript, use the const keyword. Syntax const CONSTANT_NAME = value; Example const MY_VAL = 5; console.log("MY_VAL:", MY_VAL); // This will throw an error try { MY_VAL = 10; } catch (error) { console.log("Error:", error.message); } MY_VAL: 5 Error: Assignment to constant variable. Key Points As shown above, MY_VAL is a constant with value 5 assigned. Attempting to reassign another value to a constant ...
Read MoreHow to get Natural logarithm of 10 in JavaScript?
To get the natural logarithm of 10 in JavaScript, use the Math.LN10 property. This built-in constant returns the natural logarithm of 10, which is approximately 2.302585092994046. Syntax Math.LN10 Return Value Returns a number representing the natural logarithm of 10 (ln(10) ≈ 2.302585092994046). Example JavaScript Math LN10 Property ...
Read MoreHow to set listStyleImage, listStylePosition, and listStyleType in one declaration with JavaScript?
To set the list properties in a single declaration, use the listStyle property in JavaScript. This shorthand property allows you to set listStyleType, listStylePosition, and listStyleImage all at once. Syntax element.style.listStyle = "type position image"; Parameters The listStyle property accepts up to three values: listStyleType: disc, circle, square, decimal, none, etc. listStylePosition: inside, outside listStyleImage: url() or none Example: Setting Type and Position Apple ...
Read MoreCan a user disable HTML5 sessionStorage?
Yes, users can disable HTML5 sessionStorage in their browsers. When disabled, attempts to use sessionStorage will either throw errors or fail silently, depending on the browser implementation. How Users Can Disable sessionStorage Different browsers provide various methods to disable DOM storage, which affects both localStorage and sessionStorage: Firefox Type "about:config" in the address bar and press Enter Search for "dom.storage.enabled" Right-click and toggle to "false" to disable DOM Storage Chrome Go to Settings → Privacy and security → Site Settings Click "Cookies and site data" Select "Block third-party cookies" or "Block all cookies" ...
Read MoreHTML5 preload attribute
The HTML5 preload attribute controls how much video or audio content should be loaded when the page loads, before the user plays the media. This helps optimize page loading performance and user experience. Syntax Preload Values Value Behavior Use Case none No data is loaded until user plays Save bandwidth, slow connections metadata Only duration, dimensions loaded Show video info without full download auto Entire media file is downloaded Media likely to be played immediately Example: No Preload ...
Read MoreThe Set Class in Javascript
JavaScript's built-in Set class is a collection of unique values that allows you to store distinct elements of any type. Unlike arrays, Sets automatically prevent duplicate values and provide efficient methods for adding, removing, and checking element existence. Creating a Set You can create a Set using the new Set() constructor, optionally passing an iterable like an array: // Empty set let mySet = new Set(); // Set from array let numbersSet = new Set([1, 2, 3, 4, 4, 5]); console.log(numbersSet); // Duplicates are automatically removed let wordsSet = new Set(['hello', 'world', 'hello']); console.log(wordsSet); ...
Read MoreWeekday as a number in JavaScript?
In JavaScript, the getDay() method from the Date object returns the weekday as a number from 0 to 6, where Sunday is 0, Monday is 1, and so on. Syntax dateObject.getDay() The method returns an integer representing the day of the week: 0 = Sunday 1 = Monday 2 = Tuesday 3 = Wednesday 4 = Thursday 5 = Friday 6 = Saturday Example 1: Current Date Weekday Get the ...
Read More