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 185 of 534
How to return all matching strings against a RegEx in JavaScript?
In JavaScript, regular expressions (RegEx) are powerful tools for pattern matching in strings. While string.search() returns the position of the first match, there are multiple methods to return all matching strings or substrings against a RegEx pattern. Using string.search() Method The search() method returns the index of the first match, or -1 if no match is found. Syntax let index = string.search(expression) Parameters string − The string to be searched expression − The regular expression pattern to match Example ...
Read MoreHow to set the cursor to wait in JavaScript?
In this article, we are going to look at how to set the cursor to wait in JavaScript. The wait cursor provides visual feedback to users that a process is running and prevents them from accidentally triggering multiple actions. Setting the cursor to wait is essential for improving user experience during operations like form submissions, file uploads, or API calls. JavaScript allows us to dynamically control cursor appearance using the CSS cursor property. Common Use Cases Here are typical scenarios where the wait cursor is beneficial: Processing payments to prevent double submissions ...
Read MoreHow to swap variables using Destructuring Assignment in JavaScript?
The Destructuring assignment is a feature that was introduced in the ECMAScript 2015. This feature lets the user extract the contents of the array, and properties of an object into distinct variables without actually writing the repetitive code. This assignment lets the expression unpack values from arrays, and properties into distinct variables. One of the most elegant use cases is swapping variables without using a temporary variable. Traditional Variable Swapping Before destructuring, swapping variables required a temporary variable: Traditional Variable Swap ...
Read MoreHow to use Static Variables in JavaScript?
The keyword "static" is used for defining static methods or properties of a class in JavaScript. Static members belong to the class itself rather than to instances of the class, meaning you can access them without creating an object. Static variables maintain a single value that is shared across all instances of the class. Unlike instance variables, static variables are initialized when the class is first loaded and retain their value throughout the program's execution. Note − Static variables can be reassigned and modified, unlike const variables which are immutable after initialization. Syntax class ClassName ...
Read MoreHow to use the "in" operator in JavaScript?
In this article, we are going to explore the 'in' operator and how to use it in JavaScript. The in operator is an inbuilt operator in JavaScript that is used for checking whether a particular property exists in an object or not. It will return true if the property exists, else false is returned. Syntax prop in object Parameters This operator accepts the following parameters as described below − prop − This parameter holds the string or symbol that represents a property ...
Read MoreWhat are JavaScript Classes and Proxies?
JavaScript Classes and Proxies are powerful ES6+ features that enhance object-oriented programming and metaprogramming capabilities. Classes provide a cleaner syntax for creating objects and implementing inheritance, while Proxies allow you to intercept and customize operations on objects. JavaScript Classes Classes in JavaScript are syntactic sugar over the existing prototype-based inheritance. They use the class keyword instead of functions and must be declared before use, unlike function declarations which are hoisted. Class Declaration Syntax class ClassName { constructor(property1, property2) { this.property1 = property1; ...
Read MoreWhat are JavaScript Factory Functions?
A factory function is a function that creates and returns an object. Unlike constructor functions, factory functions don't require the new keyword and don't use this to reference object properties. Factory functions are a simple and flexible way to create objects in JavaScript. They can include properties, methods, and default values, making object creation more convenient and reusable. Key Features Factory functions offer several advantages: No need for the new keyword No this binding issues Can contain private variables through closures Return objects directly Allow for easy object customization Basic Syntax ...
Read MoreWhat are the Pros and Cons of JavaScript Frameworks?
JavaScript has revolutionized web development over the past 25 years, with JavaScript frameworks becoming essential tools for modern developers. These frameworks provide structured approaches to building applications, offering both significant advantages and notable challenges. In this article, we'll explore what JavaScript frameworks are, their common use cases, and analyze the pros and cons of popular frameworks to help you make informed decisions for your projects. What are JavaScript Frameworks? JavaScript frameworks are pre-written code libraries that provide a foundation for building JavaScript applications. They offer developers a structured approach to development by providing: ...
Read MoreWhat is a typical use case for JavaScript anonymous functions?
In this article, we are going to explore the anonymous functions in JavaScript and their typical use cases. An anonymous function is a function without a name that can be stored in variables, passed as arguments, or used as return values. Anonymous functions are incredibly useful in JavaScript for callbacks, event handlers, functional programming methods like map(), filter(), and situations where you need a function only once. Syntax // Function expression let variable = function() { // code here }; // Arrow function (ES6) let variable = () => { ...
Read MoreHow to use the debugger keyword in JavaScript?
Whenever an unexpected occurrence takes place in a JavaScript code, we need to debug it to check the cause. Debugging is a very important aspect of programming that lets you determine why a system or application behaves abnormally. It is a process of testing multiple times with different inputs and finding errors to reduce bugs from computer programs. In this article, we will be exploring the debugger keyword in JavaScript and how to use it. The debugger keyword in JavaScript is a common keyword used in debugging processes and variable inspection. When the debugger keyword is encountered and developer ...
Read More