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
Front End Technology Articles
Page 288 of 652
How does inline JavaScript work with HTML?
In this article, you will understand how inline JavaScript works with HTML. Inline JavaScript represents a code block written in between the tags in an HTML file. The advantage of using inline JavaScript in HTML files is to reduce the round trip of the web browser to the server. What is Inline JavaScript? Inline JavaScript is JavaScript code that is embedded directly within HTML documents using tags. This approach allows you to execute JavaScript without creating separate .js files, making it convenient for small scripts and quick implementations. Example 1: Basic Inline JavaScript Let ...
Read MoreHow does Promise.all() method differs from Promise.allSettled() method in JavaScript?
In this article, you will understand how Promise.all() method differs from the Promise.allSettled() method in JavaScript. The Promise.all() method takes one or multiple promises as input and returns a single Promise. This returned promise fulfills when all of the input promises are fulfilled. It rejects immediately when any of the input promises is rejected, with this first rejection reason. The Promise.allSettled() method takes one or multiple promises as input and returns a single Promise. This returned promise fulfills when all of the input promises settle (either fulfilled or rejected), returning an array of objects that describe the outcome ...
Read MoreHow does internationalization work in JavaScript?
In this article, you will understand how internationalization works in JavaScript. Internationalization is the process of preparing software so that it can support local languages and cultural settings. It can include changing the date and time format, changing the metric system format, language format, etc. JavaScript provides the Intl object which contains constructors for locale-sensitive formatting and language-sensitive string comparison. The most commonly used are Intl.DateTimeFormat for dates and Intl.NumberFormat for numbers. Date and Time Formatting Let's understand how to format dates for different locales using Intl.DateTimeFormat: var inputDate = new Date(1990, 2, 25); console.log("The ...
Read MoreHow does Implicit coercion differ from Explicit coercion in JavaScript?
In this article, you will understand how implicit coercion differs from explicit coercion in JavaScript. An implicit coercion is an automatic conversion of values from one datatype to another that JavaScript performs automatically without programmer intervention. An explicit coercion is the deliberate conversion of data type using built-in functions or operators. Implicit Coercion JavaScript automatically converts data types when needed, especially in operations involving different types. let number = 5; let text = "10"; // JavaScript automatically converts number to string let result1 = number + text; console.log("5 + '10' =", result1, typeof result1); ...
Read MoreHow does Promise.any() method differs from Promise.race() method in JavaScript?
In this article, you will understand how Promise.any() method differs from Promise.race() method in JavaScript. The Promise.any() method resolves when the first promise succeeds (fulfills), ignoring rejections until all promises fail. The Promise.race() method settles when the first promise completes, regardless of whether it succeeds or fails. Promise.any() Method Promise.any() waits for the first successful promise and ignores rejections. If all promises reject, it throws an AggregateError. console.log("Defining three promise values: promise1, promise2 and promise3"); const promise1 = Promise.resolve(1); const promise2 = new Promise((resolve, reject) => { setTimeout(resolve, 200, 'Promise Two'); }); ...
Read MoreHow many numbers in the given array are less/equal to the given value using the percentile formula in Javascript?
In this article, you will understand how to calculate the percentile of a given value in an array using JavaScript. The percentile tells us what percentage of numbers in the array are less than or equal to a specific value. Percentile Formula We use the following formula to calculate the percentile: Percentile = (n/N) * 100 Where: n = count of values less than or equal to the given value N = total number of values in the array For values equal to our target, ...
Read MoreHow to Create Dark/Light Mode for a Website using JavaScript/jQuery?
Dark mode has become essential for modern websites, as it reduces eye strain and saves battery life on mobile devices. Studies show that 70-80% of users prefer dark mode, making it a crucial feature for user experience. In this tutorial, we'll learn to create a toggle between dark and light themes using JavaScript and jQuery. We'll use CSS classes and DOM manipulation to switch themes dynamically. Syntax The core method for toggling themes uses the classList.toggle() method: document.body.classList.toggle("dark-theme"); This adds the "dark-theme" class if it doesn't exist, or removes it if it does, ...
Read MoreHow to access an object having spaces in the object's key using JavaScript?
When object keys contain spaces, you cannot use dot notation to access them. Instead, you must use bracket notation with quotes around the key name. The Problem with Spaces in Keys Dot notation requires valid JavaScript identifiers, which cannot contain spaces. Keys with spaces need bracket notation. const person = { 'first name': 'John', 'last name': 'Doe', age: 30 }; // This won't work - syntax error // console.log(person.first name); // This works - bracket notation console.log(person['first name']); console.log(person['last name']); ...
Read MoreHow to access the first value of an object using JavaScript?
In this article, you will understand how to access the first value of an object using JavaScript. The first value of an object refers to the value of the first property in the object. JavaScript provides several methods to retrieve this value, depending on whether you're working with objects or arrays. Using Object.values() for Objects The Object.values() method returns an array of all enumerable property values, making it easy to access the first value. const inputObject = {1: 'JavaScript', 2: 'Python', 3: 'HTML'}; console.log("A key-value pair object is defined and its values are: ", inputObject); ...
Read MoreHow to add a parameter to the URL in JavaScript?
In JavaScript, you can add parameters to URLs using the URLSearchParams API. There are two primary methods: append() for adding new key-value pairs and set() for adding or updating parameters. The append() method adds new key-value pairs to the URL without removing existing ones. If the same key already exists, it creates multiple entries. The set() method adds a parameter if it doesn't exist, or replaces the value if the key already exists. Unlike append(), it ensures only one value per key. Using append() Method The append() method adds new parameters while preserving existing ones: ...
Read More