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 trigger the HTML button after hitting enter button in the textbox using JavaScript?
Generally, developers add the submit button to submit the input field's text. However, if they allow users to submit the input value by pressing enter, it improves the UX of the application. Here, we will learn the general way to detect the key press using the key listener event. Afterwards, we can perform any operation whenever the user presses the enter key button. Syntax Users can follow the syntax below to detect whenever the user presses the enter key. input.addEventListener("keypress", function (event) { if (event.keyCode == 13) { ...
Read MoreJavaScript Game Development: Building a 2D Game Engine
JavaScript is a versatile programming language that can be used for various applications, including game development. In this article, we will dive into the exciting world of JavaScript game development and explore the process of building a 2D game engine. We will provide code examples with explanations and showcase their output to help you understand the concepts better. Understanding the Basics Before we begin building our game engine, let's familiarize ourselves with some fundamental concepts of game development. In a 2D game, we typically deal with objects, sprites, game loops, and collision detection. ...
Read MoreHow to trigger the onchange event on input type=range while dragging in Firefox?
The range input allows users to select any value within a specified range. By default, the onchange event only triggers when the user releases the mouse, not during dragging. This creates poor user experience as users can't see real-time value updates. The onchange event triggers only when the user releases the mouse button, so it won't update the value while dragging the range slider. This behavior occurs in all browsers, including Firefox, Chrome, and Safari. Let's examine this problem and explore the solution using the oninput event. Problem: onchange Event Limitation In this example, the range ...
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 MoreHow 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 MoreJavaScript Machine Learning: Building ML Models in the Browser
Machine Learning (ML) has revolutionized various industries, enabling computers to learn and make predictions based on patterns and data. Traditionally, ML models were built and executed on servers or high-performance machines. However, with the advancements in web technologies, it is now possible to build and deploy ML models directly in the browser using JavaScript. In this article, we will explore the exciting world of JavaScript Machine Learning and learn how to build ML models that can run in the browser using TensorFlow.js. Understanding Machine Learning Machine Learning is a subset of Artificial Intelligence (AI) that focuses on ...
Read MoreHow to conditionally add a member to an object using JavaScript?
Objects are fundamental data structures in JavaScript, and developers often need to add properties conditionally based on certain criteria. For example, adding a "drivingLicense" property to a person object only if they are 18 or older. Here, we will explore different approaches to conditionally add members to JavaScript objects. Using the Spread Operator The spread operator provides an elegant way to conditionally add properties during object creation or update. Syntax let obj = { ...(condition ? { prop: 'value' } : {}) } If the condition is true, it ...
Read MoreJavaScript Program to Count Inversions of size three in a given array
In this tutorial, we will learn to count inversions of size three in a given array. An inversion of size three is a triplet of indices (i, j, k) where i < j < k but arr[i] > arr[j] > arr[k]. Problem Statement: Given an array of length n containing different numeric entries, we need to find the total number of triplets (i, j, k) such that arr[i] > arr[j] > arr[k], where i < j < k. We'll explore two approaches: a brute force method and an optimized solution using nested loops. Using the Brute Force ...
Read MoreJavaScript Program to Count Rotations Divisible by 4
In this tutorial, we will learn to count the total number of rotations divisible by 4 for the given number. Problem statement − We have given a number value. We need to rotate numbers in clockwise or anti-clockwise directions and count the total number of rotations divisible by 4. Here, we will learn two different approaches to counting rotations divisible by 4. Understanding Number Rotation When we rotate a number, we move digits from one position to another. For example, rotating 1234 clockwise gives us: 4123, 3412, 2341, and back to 1234. Each rotation creates a ...
Read More