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
Javascript Articles
Page 10 of 534
How to trigger the setInterval loop immediately using JavaScript?
The setInterval() method allows us to continuously trigger a callback function after every particular time period. We can pass the callback function as the first parameter to trigger after every time period, and the time period in milliseconds as a second parameter. The setInterval() method invokes the callback function after a particular number of milliseconds for the first time. Now, the problem is we need to invoke the callback function instantly for the first time at 0 milliseconds, and after that, we need to invoke it continuously in the given time period. The Default Behavior Problem In ...
Read MoreHow to check if CSS property is supported in browser using JavaScript?
CSS properties aren't supported uniformly across all browsers. JavaScript's CSS.supports() method lets you check if a specific CSS property and value combination is supported by the current browser, preventing layout issues and enabling feature detection. Syntax CSS.supports("property: value"); CSS.supports("property", "value"); Parameters property − The CSS property name (e.g., "display", "grid-template-columns", "backdrop-filter") value − The property value to test (e.g., "flex", "repeat(3, 1fr)", "blur(5px)") Return Value Returns true if the browser supports the property-value combination, false otherwise. Method 1: Direct Property Testing Test specific CSS ...
Read MoreHow to use Ejs in JavaScript?
EJS is a templating language that allows us to generate HTML markup using plain JavaScript. It provides a simple and intuitive way to generate dynamic content in our web applications, making it easier to manage and organize our code. EJS is easy to use and can be integrated into any JavaScript project with just a few steps. In this tutorial, we will learn the basics of how to use EJS in JavaScript, including how to set up our project, create an EJS template, and render the template to generate dynamic HTML output. Steps to Use EJS in a ...
Read MoreHow to use SolverJS?
SolverJS is a comprehensive JavaScript package that provides a range of functions to help us solve common math problems. We know that web applications often require complex logic to function properly, and these logical solutions can easily become long and difficult to manage. This is where Solver JS comes in - it includes a wide range of general and complex mathematical solutions and provides functions not available in standard JavaScript. In this tutorial, we will learn how to use Solver JS and its various functions. The package includes functions such as date conversions, keyword extraction, string case checking, URL ...
Read MoreHow to stop event propagation with inline onclick attribute in JavaScript?
Event propagation in JavaScript causes events to bubble up from child elements to their parents. When you have nested elements with click handlers, clicking a child element triggers both the child and parent handlers. The stopPropagation() method prevents this bubbling behavior. Understanding Event Propagation Let's see how event propagation works with nested elements: .parent-div { width: 300px; height: 150px; ...
Read MoreHow to test a value x against predicate function and returns fn(x) or x in JavaScript?
Testing a value x against a predicate function means checking if x meets a specific condition. If the condition is true, we apply a transformation function to x and return the result. Otherwise, we return the original value x unchanged. Syntax The basic syntax uses the ternary operator to test a value against a predicate function: let result = predicate(x) ? operation(x) : x; Where predicate(x) returns true/false, and operation(x) transforms the value when the predicate passes. Basic Example Here's a simple example that squares numbers greater than 5, otherwise returns the ...
Read MoreHow to uniquely identify computers visiting web site in JavaScript?
Whenever we create any application or website, we need to uniquely identify computers visiting the website. There are many benefits to uniquely identifying computers. For example, you can provide free trial services when a user visits your website for the first time from a new device. When they visit again, you can ask users to upgrade to premium or subscribe to your application. Here, we will use cookies to identify computers visiting our website. What are Cookies? Cookies allow developers to store user information in the browser. We can send data from the server to the ...
Read MoreHow to upload file without form using JavaScript?
Sometimes, developers need to upload files without creating traditional HTML forms. This is useful for drag-and-drop interfaces, single-click uploads, or when building custom file upload components. In this tutorial, we'll explore methods to upload files directly using JavaScript. Using FormData() Object and AJAX Request The FormData object allows us to store file data in key-value pairs, similar to form submissions. We can capture files from HTML input elements and send them to the server using AJAX without wrapping them in a form. Syntax let formData = new FormData(); formData.append("file", uploadedFile); $.ajax({ ...
Read MoreInsert a character after every n characters in JavaScript
Insertion of a specific character after every n characters in JavaScript is an easy-to-understand concept that gives us better understanding of JavaScript's string manipulation functions. Here n can be any whole number ranging from 1 to less than the length of the string. In this article, we'll explore different methods to insert a "-" character after every 5 characters in a string. Method 1: Using the slice() Method The slice() method extracts a portion of a string and returns a new string. It accepts two parameters: the starting index and the ending index (exclusive). let ...
Read MoreHandling Promise rejection with a catch while using await in JavaScript
In JavaScript, when working with async/await syntax, you need proper error handling for rejected promises. While Promise chains use .catch(), async/await functions require try-catch blocks to handle promise rejections. Basic Promise Creation Let's start with the fundamental syntax for creating promises: let testPromise = new Promise((resolve, reject) => { // perform some operation // resolve(value) for success // reject(error) for failure }); Example: Promise with .then() and .catch() Here's how traditional promise handling works with .then() and .catch() methods: ...
Read More