Articles on Trending Technologies

Technical articles with clear explanations and examples

How do I print a message to the error console using JavaScript?

Ali
Ali
Updated on 15-Mar-2026 364 Views

To print messages to the browser console in JavaScript, use the console object. Different methods display messages with varying styles and importance levels. Basic Console Methods Here are the main console methods for displaying messages: console.log("This is a regular message"); console.error("This is an error message"); console.warn("This is a warning message"); console.info("This is an info message"); This is a regular message This is an error message (displayed in red) This is a warning message (displayed in yellow/orange) This is an info message (displayed in blue) Error Console Specifically To print specifically ...

Read More

How to access cookies using document object in JavaScript?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 8K+ Views

In JavaScript, you can access and read cookies using the document.cookie property. This property returns a string containing all cookies stored in the browser for the current domain. The document.cookie string contains a list of name=value pairs separated by semicolons, where each name represents a cookie name and its corresponding value is the cookie's string value. In this article, we will learn how to access cookies using the document object in JavaScript. Syntax document.cookie Return Value: A string containing all cookies for the current domain, formatted as semicolon-separated name=value pairs. Reading All ...

Read More

How do I print debug messages in the Google Chrome JavaScript Console?

Ali
Ali
Updated on 15-Mar-2026 419 Views

To print debug messages in the Google Chrome JavaScript Console, you can use various console methods. These methods help you output different types of information for debugging purposes. Setting Up Console Compatibility First, ensure console methods exist to prevent errors in older browsers: if (!window.console) console = {}; console.log = console.log || function(){}; console.warn = console.warn || function(){}; console.error = console.error || function(){}; Basic Console Methods The most commonly used console methods in Chrome are: // Basic logging console.log("This is a general log message"); // Warning message console.warn("This is a ...

Read More

How to clear all cookies with JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 22K+ Views

In this tutorial, we will learn to clear all cookies using JavaScript. Cookies are text data stored in the browser that help websites remember user information like usernames, authentication tokens, and preferences. When a user visits a webpage for the first time, it retrieves user information from the server and stores it as cookies in the browser. On subsequent visits, the webpage can access this stored data instead of making server requests, making the application faster and more efficient. Modern browsers typically allow cookies up to 4KB in size, with limits on the total number: Chrome allows around ...

Read More

How to set cookies expiry date in JavaScript?

radhakrishna
radhakrishna
Updated on 15-Mar-2026 6K+ Views

Setting an expiration date for cookies allows them to persist beyond the current browser session. Without an expiration date, cookies are deleted when the browser closes. You can set the expiry date using the expires attribute in the cookie string. Syntax document.cookie = "name=value; expires=date; path=/"; Setting Cookie with 1 Month Expiry Here's how to create a cookie that expires after one month: function WriteCookie() { var now = new Date(); ...

Read More

How to create cookies in JavaScript?

Rishi Rathor
Rishi Rathor
Updated on 15-Mar-2026 894 Views

Using cookies is the most efficient method of remembering and tracking preferences, purchases, commissions, and other information required for better visitor experience or site statistics. The simplest way to create a cookie is to assign a string value to the document.cookie object, which looks like this: document.cookie = "key1=value1;key2=value2;expires=date"; Here the expires attribute is optional. If you provide this attribute with a valid date or time, then the cookie will expire on a given date or time and thereafter, the cookies' value will not be accessible. Note − Cookie values may not include semicolons, ...

Read More

How does JavaScript .prototype work?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 500 Views

In JavaScript, every function has a prototype property that serves as a template for creating objects. Understanding prototypes is essential for mastering JavaScript's object-oriented programming capabilities and inheritance patterns. What is a Prototype? A prototype is an object that exists on every function in JavaScript. When you create objects using constructor functions, they inherit properties and methods from the function's prototype. This enables code reusability and efficient memory usage. Consider creating multiple objects with similar properties: Basic Object Creation Creating Objects Without Prototype ...

Read More

How to turn a String into a JavaScript function call?

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 591 Views

In JavaScript, you can dynamically call a function by converting a string containing the function name into an actual function call. This is useful when function names are determined at runtime. Using window Object (Browser) The most common method in browsers is using the window object to access globally defined functions: function myFunction(argument) { alert('My function ' + argument); } ...

Read More

Smart / self-overwriting / lazy getters in javaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 802 Views

In this tutorial, let us discuss the smart, self-overwriting, or lazy-getters in JavaScript. A getter binds the property of an object to a function, but the getter will not calculate the property value until we access it. Smart or lazy getters are a special pattern where the getter replaces itself after the first computation, avoiding recalculation and improving performance. The getter helps when we need to get some dynamic value without an explicit call. Smart getters are particularly useful for expensive operations that should only run once. Syntax { get prop() {} } { get ...

Read More

How can I Execute JavaScript at the Command Prompt?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 13K+ Views

To execute JavaScript at the command prompt, you can use several methods depending on your environment. This article covers three practical approaches: running JavaScript files through Node.js, executing code directly in the Node.js REPL, and using the browser console for quick testing. In this article, we'll explore how to execute JavaScript at the command prompt using different methods. Methods to Run JavaScript at Command Line Here are three methods to execute JavaScript at the command prompt, each with detailed explanations and examples: Running JavaScript Files with Node.js ...

Read More
Showing 18991–19000 of 61,297 articles
Advertisements