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 429 of 534
Explain 'dotAll' flag for regular expressions in JavaScript
The dotAll flag returns true or false depending upon if the s flag has been set in the regular expression. The s flag enables "dotAll" mode, where the dot . metacharacter matches any character, including newlines. What is the dotAll Flag? By default, the dot . in regular expressions matches any character except newlines. When the s flag is used, the dot can also match newline characters (, \r, etc.), making it truly match "any" character. Syntax regex.dotAll // Returns true if 's' flag is set, false otherwise Example: Checking dotAll Flag ...
Read MoreHow to import and export a module/library in JavaScript?
Note − To run this example you will need to run a localhost server. JavaScript modules allow you to break code into separate files and share functionality between them using export and import statements. This promotes code reusability and better organization. Example INDEX.html Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; ...
Read MoreNaN and Infinity example in JavaScript
In JavaScript, NaN (Not-a-Number) and Infinity are special numeric values that represent invalid or infinite calculations. Understanding these values is crucial for handling mathematical operations and validation. What is NaN? NaN represents a value that is "Not-a-Number". It occurs when a mathematical operation fails or produces an undefined result. NaN Examples let results = document.getElementById('nanResults'); ...
Read MoreHow to search for a string in JavaScript?
JavaScript provides several methods to search for strings. The most common approaches are search(), indexOf(), includes(), and match(). Using search() Method The search() method returns the index of the first match or -1 if not found. It supports regular expressions. String Search Example The spring season is about to come. SEARCH FOR 'spring' ...
Read MoreHow to print positive and negative infinity values in JavaScript?
In JavaScript, infinity values represent numbers that exceed the maximum finite value. JavaScript provides built-in constants to handle positive and negative infinity values. JavaScript Infinity Constants JavaScript has two built-in constants for infinity values: Infinity or Number.POSITIVE_INFINITY - represents positive infinity -Infinity or Number.NEGATIVE_INFINITY - represents negative infinity Basic Example JavaScript Infinity Values JavaScript Infinity Values ...
Read MoreWhat are associative Arrays in JavaScript?
Associative arrays are basically objects in JavaScript where indexes are replaced by user-defined keys. They do not have a length property like normal arrays and cannot be traversed using a normal for loop. What are Associative Arrays? In JavaScript, what we call "associative arrays" are actually objects. Unlike traditional arrays that use numeric indexes, associative arrays use string keys to access values. This makes them perfect for storing key-value pairs where you need meaningful identifiers. Creating Associative Arrays You can create associative arrays using object literal syntax or by assigning properties to an empty object: ...
Read MoreExplain common code blocks in JavaScript switch statement?
Common code blocks in JavaScript switch statements allow multiple cases to share the same execution code. This is achieved by omitting the break statement, causing execution to "fall through" to subsequent cases. What are Common Code Blocks? Common code blocks occur when multiple case values need to execute the same code. Instead of duplicating code, you can group cases together by omitting break statements. Syntax switch (expression) { case value1: case value2: case value3: // ...
Read MoreExplain Strict Comparison in JavaScript switch statement?
The JavaScript switch statement performs strict comparison (===) to match values. This means both value and type must be identical for a case to execute. If no strict match is found, the default case runs. Understanding Strict Comparison Strict comparison checks both value and type. For example, the number 1 is not equal to the string "1" in strict comparison: Strict Comparison Demo // Demonstrating strict vs loose comparison ...
Read MoreExplain JavaScript Regular Expression modifiers with examples
JavaScript regular expression modifiers are optional flags that modify how the pattern matching behaves. These modifiers enable features like case-insensitive matching, global searching, and multiline matching. Available Modifiers Modifier Name Description ...
Read MoreHow to test and execute a regular expression in JavaScript?
JavaScript provides two main methods for testing and executing regular expressions: test() and exec(). The test() method returns a boolean indicating if a pattern matches, while exec() returns detailed match information or null. Regular Expression Methods There are two primary ways to work with regular expressions in JavaScript: test() - Returns true/false if pattern matches exec() - Returns match details or null Example: Using test() and exec() Regular Expression Testing ...
Read More