
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6710 Articles for Javascript

937 Views
You cannot skip a character in a capture group. A match is always consecutive, even when it contains things like zero-width assertions.ExampleHowever, you can access the matched groups in a regular expression like the following code − var str = "Username akdg_amit"; var myReg = /(?:^|\s)akdg_(.*?)(?:\s|$)/g; var res = myReg.exec(str); document.write(res[1]);

463 Views
To get a JavaScript stack trace, simply add the following in your code. It will display the stack trace −Example Live Demo function stackTrace() { var err = new Error(); return err.stack; } console.log(stackTrace()); document.write(stackTrace()); Stacktrace prints above. Output

3K+ Views
This tutorial teaches us to get a JavaScript stack trace when we throw an exception. Usually, the developer uses the stack trace to identify the errors while executing the program's code. However, we use the stack trace to debug the program.Using the stack trace, we can get knowledge of any kind of exceptions, such as constructor error, naming error, etc., in our program, and we can correct them.Before we approach analyzing the error using the stack trace, we should know how to stack trace works.How does the call stack trace works?The stack is the primary data structure that follows the ... Read More

2K+ Views
In this tutorial, we will learn how to catch syntax errors in JavaScript. In JavaScript, we get will errors if we write any mistakes in code. Like, ReferenceError, i.e., when we call a variable that does not exist in our code. TypeError i.e. when we tried to change the value which is immutable or try to use a variable in an appropriate way. SyntaxError i.e. when we tried to interpret invalid code. We will learn more about this error in detail below. What is Syntax Error? A syntax error is thrown when there is a glitch in ... Read More

12K+ Views
To catch all JavaScript errors, we can use the window.onerror() method which acts like a global try-catch statement. The onerror event handler was the first feature to facilitate error handling in JavaScript. The error event is fired on the window object whenever an exception occurs on the page. The onerror event handler provides three pieces of information to identify the exact nature of the error − Error message − The same message that the browser would display for the given error URL − The file in which the error occurred Line number− The line number in the given ... Read More

3K+ Views
This tutorial teaches us how to remove the text part between two parts of a string with JavaScript, basically, we are given two ends that can be a string or a character and we have to remove the string lying in between them. In this tutorial, we are going to use the regular expression or JavaScript Regex to remove the text between two characters. We are going to use the replace() function of JavaScript. Syntax Let’s see the syntax of removing part of a string in between two characters or sub-strings of a given string using JavaScript Regex − var ... Read More

189 Views
To find multiple matches, write a JavaScript regular expression. You can try to run the following code to implement regular expression for multiple matches −Example var url = 'https://www.example.com/new.html?ui=7&demo=one&demo=two&demo=three four', a = document.createElement('a'); a.href = url; var demoRegex = /(?:^|[&;])demo=([^&;]+)/g, matches, demo = []; while (matches = demoRegex.exec(a.search)) { demo.push(decodeURIComponent(matches[1])); } document.write(demo);

258 Views
To remove spaces in JavaScript, you can try to run the following regular expression. It removes the spaces from a string −Example Live Demo var str = "Welcome to Tutorialspoint"; document.write(str); //Removing Spaces document.write(""+str.replace(/\s/g, '')); Output

3K+ Views
In this tutorial, we will explore how we can replace a particular sub string in a string by using regular expressions in JavaScript. Sometimes we may want to replace a recurrent sub string in a string with something else. In such cases, regular expressions can be beneficial. Before using them to solve our current problem, let us see what regular expressions exactly are. Regular expressions are basically a pattern of characters that can be used to search different occurrences of that pattern in a string. Regular expressions make it possible to search for a particular pattern in a stream of ... Read More