How can I store JavaScript objects in cookies?

Shubham Vora
Updated on 15-Mar-2026 23:18:59

13K+ Views

This tutorial will teach us to store JavaScript objects into the cookies. The cookies are the information of website visitors stored in text files. There is a particular mechanism to store the cookies of users' browsers. When new visitors visit the website, the server generates the text and sends it to the user. After that, when users allow access to the web page to retrieve the cookies, the server stores all user information in the text files. Cookies store the user's search history or other information for a better experience. For example, Google stores the user's search history to ... Read More

What is onsubmit event in JavaScript?

V Jyothi
Updated on 15-Mar-2026 23:18:59

4K+ Views

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 More

Find digits not between the brackets using JavaScript Regular Expressions?

Sravani Alamanda
Updated on 15-Mar-2026 23:18:59

281 Views

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 More

encodeURIComponent() function in JavaScript

karthikeya Boyini
Updated on 15-Mar-2026 23:18:59

181 Views

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 More

JavaScript symbol.description property

AmitDiwan
Updated on 15-Mar-2026 23:18:59

171 Views

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 More

How can I remove a child node in HTML using JavaScript?

AmitDiwan
Updated on 15-Mar-2026 23:18:59

264 Views

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 More

If string includes words in array, remove them JavaScript

AmitDiwan
Updated on 15-Mar-2026 23:18:59

871 Views

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 More

Call a JavaScript class object with variable?

AmitDiwan
Updated on 15-Mar-2026 23:18:59

1K+ Views

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 More

Finding least number of notes to sum an amount - JavaScript

AmitDiwan
Updated on 15-Mar-2026 23:18:59

845 Views

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 More

What are secured cookies in JavaScript?

Daniol Thomas
Updated on 15-Mar-2026 23:18:59

2K+ Views

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 More

Advertisements