Javascript Articles

Page 273 of 534

How to create Empty Values String in JavaScript?

seetha
seetha
Updated on 15-Mar-2026 3K+ Views

In JavaScript, there are several ways to create empty string values. An empty string is a string with zero characters, represented by two quotation marks with nothing between them. Syntax let emptyString = ""; // Double quotes let emptyString = ''; // Single quotes let emptyString = ``; // Template literals let emptyString = String(); // String constructor Example: Creating Empty Strings ...

Read More

How to call a function in JavaScript?

Nancy Den
Nancy Den
Updated on 15-Mar-2026 1K+ Views

JavaScript allows us to write our own functions as well. To invoke a function somewhere later in the script, you would simply need to write the name of that function. Function Declaration Before calling a function, you need to declare it. Here's the basic syntax: function functionName() { // Code to execute } Calling a Function Once declared, you can call a function by writing its name followed by parentheses: function sayHello() ...

Read More

How to write JavaScript Regular Expression for multiple matches?

Nikitha N
Nikitha N
Updated on 15-Mar-2026 277 Views

To find multiple matches in JavaScript, use the global flag (g) with regular expressions. The exec() method can be called repeatedly to find all matches in a string. Syntax let regex = /pattern/g; let matches; while ((matches = regex.exec(string)) !== null) { // Process each match } Example: Extracting URL Parameters This example extracts all demo parameters from a URL query string: var url = 'https://www.example.com/new.html?ui=7&demo=one&demo=two&demo=three'; var a = document.createElement('a'); a.href = url; var demoRegex = /(?:^|[&;])demo=([^&;]+)/g; var matches; var demo = []; ...

Read More

What is function overloading in JavaScript?

Ankitha Reddy
Ankitha Reddy
Updated on 15-Mar-2026 2K+ Views

JavaScript does not support function overloading like other programming languages such as Java or C++. When you define multiple functions with the same name, JavaScript keeps only the last defined function. What Happens with Same Function Names Let's see what happens when we define multiple functions with the same name: function funcONE(x, y) { return x * y; } function funcONE(z) { return z; } // Only the last function definition is kept console.log(funcONE(5)); // prints 5 console.log(funcONE(5, 6)); // prints ...

Read More

How much should be a JavaScript Line Length?

Nitya Raut
Nitya Raut
Updated on 15-Mar-2026 842 Views

JavaScript line length refers to how many characters should fit on a single line of code. Following proper line length guidelines makes your code more readable and maintainable. Recommended Line Length The standard practice is to keep JavaScript lines under 80 characters. Some modern style guides allow up to 100 or 120 characters, but 80 remains the most widely adopted standard for better readability across different editors and devices. Breaking Long Lines When a statement exceeds the character limit, break it after a comma or operator, not in the middle of a variable name or string. ...

Read More

How to create a table caption with JavaScript DOM?

Jai Janardhan
Jai Janardhan
Updated on 15-Mar-2026 670 Views

To create a table caption using JavaScript DOM, use the createCaption() method on a table element. This method adds a element to the table, which displays as a title above the table content. Syntax table.createCaption() Return Value Returns the newly created element, which can be styled or modified with text content. Example Here's how to create a table caption dynamically using JavaScript: function captionFunc(x) { ...

Read More

Which is the JavaScript RegExp to find any alternative text?

Nikitha N
Nikitha N
Updated on 15-Mar-2026 291 Views

To match any of the specified alternatives in JavaScript, use the alternation operator | within parentheses. This pattern allows you to find multiple possible text options in a single regular expression. Syntax (option1|option2|option3) The pipe symbol | acts as an OR operator, matching any one of the alternatives listed within the parentheses. Example Here's how to find alternative text patterns using JavaScript RegExp: JavaScript Regular Expression var myStr = "one, ...

Read More

How to perform Multiline matching with JavaScript RegExp?

Moumita
Moumita
Updated on 15-Mar-2026 700 Views

To perform multiline matching in JavaScript, use the m flag with regular expressions. This flag makes ^ and $ anchors match the beginning and end of each line, not just the entire string. Syntax /pattern/m new RegExp("pattern", "m") How the m Flag Works Without the m flag, ^ matches only the start of the string and $ matches only the end. With the m flag, they match line boundaries created by (newline) characters. Example: Basic Multiline Matching JavaScript Regular ...

Read More

What is the usage of in operator in JavaScript?

Arushi
Arushi
Updated on 15-Mar-2026 200 Views

The in operator is used in JavaScript to check whether a property exists in an object or not. It returns true if the property is found, and false otherwise. Syntax propertyName in object Basic Example Here's how to use the in operator to check for properties in objects: var emp = {name: "Amit", subject: "Java"}; document.write("name" in emp); document.write(""); document.write("subject" in emp); document.write(""); document.write("age" in emp); document.write(""); document.write("MAX_VALUE" in Number); true true false true Checking Array Indices The in ...

Read More

With JavaScript RegExp find a character except newline?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 299 Views

To find a character except for a newline, use the dot metacharacter . (period). The dot matches any single character except the newline character (). Syntax /./ // Matches any character except newline /.+/ // Matches one or more characters except newline /a.b/ // Matches 'a', any character, then 'b' Example JavaScript Regular Expression ...

Read More
Showing 2721–2730 of 5,340 articles
« Prev 1 271 272 273 274 275 534 Next »
Advertisements