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 321 of 534
Which event occurs in JavaScript when an element's content is cut?
The oncut event occurs when an element's content is cut using Ctrl+X or the right-click context menu. This event is commonly used with input fields, textareas, and other editable elements to track when users cut text. Syntax element.oncut = function() { // Code to execute when content is cut }; // Or using addEventListener element.addEventListener('cut', function(event) { // Code to execute when content is cut }); Example: Basic oncut Event Cut Event Example ...
Read MoreGet filename from string path in JavaScript?
We need to write a function that takes in a string file path and returns the filename. Filename usually lives right at the very end of any path, although we can solve this problem using regex but there exists a simpler one-line solution to it using the string split() method of JavaScript and we will use the same here. Let's say our file path is − "/app/base/controllers/filename.js" Using split() Method Following is the code to get file name from string path − const filePath = "/app/base/controllers/filename.js"; const extractFilename = (path) => { ...
Read MoreHow to set the inward offsets of the image border with JavaScript?
In this tutorial, we will learn how to set the inward offsets of the image border with JavaScript. An image can be set in the border as a border image using CSS properties. The border image can be set using different parameters. To set the inward offsets of the image border, use the borderImageSlice property in JavaScript. We will see two different approaches to setting up the inward offsets of the image border with JavaScript − The borderImageSlice Property The setProperty Method Using the borderImageSlice Property ...
Read MoreHow null is converted to Boolean in JavaScript?
In JavaScript, null is a primitive value that represents an intentional absence of any object value. When converting null to Boolean, it always evaluates to false because null is considered a falsy value in JavaScript. Understanding Falsy Values In JavaScript, null is one of the falsy values along with undefined, 0, "" (empty string), NaN, and false. All falsy values convert to false when used in Boolean contexts. Using the Boolean() Function The Boolean() function converts any value to its Boolean equivalent. For null, it always returns false. Syntax Boolean(null) Example ...
Read MoreHow is NaN converted to Boolean in JavaScript?
In JavaScript, NaN (Not a Number) is a special numeric value that represents an invalid number. When converted to Boolean, NaN is always considered a falsy value. This article explores three methods to convert NaN to Boolean. Using the Boolean() Function Using the !! Operator Using the NOT Operator and isNaN() Method Understanding NaN as a Falsy Value In JavaScript, NaN is one of the falsy values (along with false, 0, "", null, and undefined). This means it always converts to false in Boolean contexts. Using the Boolean() Function The Boolean() function converts ...
Read MoreWhat is the role of clientX Mouse Event in JavaScript?
The clientX property returns the horizontal (x-axis) coordinate of the mouse pointer relative to the current viewport when a mouse event occurs. Unlike other coordinate properties, clientX is measured from the left edge of the browser's visible area, not including scrollbars. Syntax event.clientX Return Value Returns a number representing the horizontal pixel position of the mouse pointer relative to the viewport's left edge. Example: Getting Mouse Coordinates on Click clientX Mouse Event ...
Read MoreCombine objects and delete a property with JavaScript
We have the following array of objects that contains two objects and we are required to combine both objects into one and get rid of the chk property altogether: const err = [ { "chk" : true, "name": "test" }, { "chk" : true, "post": "test" } ]; ...
Read MoreHow -Infinity is converted to Number in JavaScript?
In JavaScript, -Infinity is a special numeric value representing negative infinity. When converted using the Number() method, it remains -Infinity since it's already a valid number type. Understanding -Infinity -Infinity is a built-in JavaScript constant that represents the mathematical concept of negative infinity. It's already of type "number", so converting it with Number() simply returns the same value. -Infinity Conversion Converting -Infinity to Number var myVal = -Infinity; ...
Read MoreHow to create a function which returns only even numbers in JavaScript array?
Here, we need to write a function that takes one argument, which is an array of numbers, and returns an array that contains only the numbers from the input array that are even. So, let's name the function as returnEvenArray, the code for the function will be − Example const arr = [3, 5, 6, 7, 8, 4, 2, 1, 66, 77]; const returnEvenArray = (arr) => { return arr.filter(el => { return el % 2 === 0; }) }; ...
Read MoreWhat is the role of ctrlKey Mouse Event in JavaScript?
The ctrlKey mouse event property is a boolean value that indicates whether the CTRL key was pressed when a mouse event occurred. This property is available on all mouse events like click, mousedown, mouseup, etc. Syntax event.ctrlKey Return Value true - if the CTRL key was pressed during the mouse event false - if the CTRL key was not pressed during the mouse event Example The following example demonstrates how to detect if the CTRL key is pressed when clicking on an element: ...
Read More