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
Articles on Trending Technologies
Technical articles with clear explanations and examples
What is onsubmit event in JavaScript?
The onsubmit event is an event that occurs when you try to submit a form. You can put your form validation against this event type. The following example shows how to use onsubmit. Here we are calling a validate() function before submitting a form data to the web server. If validate() function returns true, the form will be submitted, otherwise, it'll not submit the data. Syntax // form elements // Or using JavaScript form.onsubmit = function(event) { // validation logic return true; ...
Read MoreFind digits not between the brackets using JavaScript Regular Expressions?
In JavaScript, regular expressions with negated character classes [^0-9] are used to find characters that are NOT digits. The caret ^ inside square brackets creates a negated character class, matching any character except those specified. Regular expressions (RegExp) are powerful pattern-matching tools introduced in ES1 and supported by all modern browsers. They're commonly used for string validation, search operations, and text manipulation. Syntax The syntax for matching non-digits is: new RegExp("[^0-9]") // or simply /[^0-9]/ With modifiers for global matching: new RegExp("[^0-9]", "g") // or simply /[^0-9]/g ...
Read MoreencodeURIComponent() function in JavaScript
The encodeURIComponent() function accepts a string representing a URI component and encodes it by replacing special characters with percent-encoded sequences. This is essential for safely passing data in URLs. Syntax encodeURIComponent(uriComponent) Parameters uriComponent: A string to be encoded as a URI component. Return Value Returns a new string representing the encoded URI component with special characters replaced by percent-encoded sequences. Example 1: Basic Usage JavaScript Example var url = 'http://www.tutorialspoint.com/'; ...
Read MoreJavaScript symbol.description property
The symbol.description property in JavaScript returns the description string of a Symbol. Unlike Symbol.toPrimitive, the description property provides access to the optional description passed when creating a Symbol. Syntax symbol.description Return Value Returns the description string of the Symbol, or undefined if no description was provided during Symbol creation. Example: Symbol with Description Symbol Description Example Click to display symbol description... Show Description function display() { const sym1 = Symbol('user-id'); const ...
Read MoreHow can I remove a child node in HTML using JavaScript?
In JavaScript, you can remove child nodes from HTML elements using several methods. The most common approaches are removeChild() and the modern remove() method. Using removeChild() Method The removeChild() method removes a specified child node from its parent element. You need to call it on the parent element and pass the child node as a parameter. Remove Child Node body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result ...
Read MoreIf string includes words in array, remove them JavaScript
In JavaScript, you may need to remove specific words from a string based on an array of target words. This is useful for content filtering, text cleaning, or removing unwanted terms from user input. Problem Overview We need to create a function that removes all occurrences of words present in an array from a given string, while handling whitespace properly to avoid multiple consecutive spaces. Method 1: Using reduce() with Regular Expressions const string = "The weather in Delhi today is very similar to the weather in Mumbai"; const words = [ ...
Read MoreCall a JavaScript class object with variable?
In JavaScript, you can call a class constructor with variables by passing the variable as an argument. There are several ways to achieve this, including direct instantiation and using eval(). Basic Class Instantiation with Variables The most straightforward approach is to pass variables directly to the class constructor: class FirstClass { constructor(message) { this.message = message; } } var message = 'This is the Class Demo'; var object = new FirstClass(message); console.log(object.message); This is the Class ...
Read MoreFinding least number of notes to sum an amount - JavaScript
Suppose, we have a currency system where we have denominations of 1000 units, 500 units, 100 units, 50 units, 20 units, 10 units, 5 units, 2 units and 1 unit. Given a specific amount, we are required to write a function that calculates the least number of total denominations that sum up to the amount. For example, if the amount is 512, The least number of notes that will add up to it will be: 1 unit of 500, 1 unit of 10 and 1 unit of 2. So, for 512, our function should ...
Read MoreWhat are secured cookies in JavaScript?
Secured cookies in JavaScript are cookies with special security attributes that protect against common web vulnerabilities. They use two main flags: Secure and HttpOnly to enhance security. What Makes a Cookie Secured? A secured cookie has two key attributes: Secure flag - Cookie is only sent over HTTPS connections HttpOnly flag - Cookie cannot be accessed via JavaScript The Secure Attribute The Secure attribute ensures cookies are only transmitted over encrypted HTTPS connections, preventing interception over unsecured HTTP. // Setting a secure cookie (server-side example) document.cookie = "sessionId=abc123; Secure; Path=/"; ...
Read MoreWhat is the difference between parseInt(string) and Number(string) in JavaScript?
In JavaScript, parseInt() and Number() both convert strings to numbers, but they handle invalid characters differently. Understanding their behavior is crucial for proper string-to-number conversion. parseInt() Method The parseInt() method parses a string character by character and stops at the first non-digit character, returning the parsed integer portion. console.log(parseInt("765world")); console.log(parseInt("50px")); console.log(parseInt("123.45")); console.log(parseInt("abc123")); 765 50 123 NaN Number() Method Number() attempts to convert the entire string to a number. If any part of the string is invalid, it returns NaN. console.log(Number("765world")); console.log(Number("50px")); console.log(Number("123.45")); console.log(Number("123")); NaN NaN ...
Read More