Found 6685 Articles for Javascript

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

Ali
Ali
Updated on 16-Jun-2020 13:52:32

203 Views

To print a message to the error console, use the console object. Here’s an example −The following will show a red error message −console.error(message);The following gives you the default message −console.log(message);The following gives you the warning message −console.warn(message);The following gives an information message −console.info(message);Add CSS to the log message −console.log('%c Add message!, "background: green; color: white;");Use the following to print error. Consider “num” as the variable name −console.error('num=%d', num);For complete API reference, refer Console API Reference.

How to access cookies using document object in JavaScript?

Saurabh Jaiswal
Updated on 06-Jan-2023 12:58:06

7K+ Views

With JavaScript, you can easily access/ read cookies with the “document.cookie” property. Reading a cookie is just as simple as writing one because of the value of the document.cookie object is the cookie. The document.cookie string will keep a list of name=value pairs separated by semicolons, where the name is the name of a cookie and value is its string value. In this article, we will learn how to access cookies using document object in JavaScript. Syntax document.cookie Return value − All the cookies are saved in the browser in a single string. The document.cookie string will keep ... Read More

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

Ali
Ali
Updated on 16-Jun-2020 13:35:05

222 Views

To print debug messages in the Google Chrome JavaScript Console, write a script, which is not creating console functions if they do not exist −if (!window.console) console = {}; console.log = console.log || function(){}; console.warn = console.warn || function(){}; console.error = console.error || function(){};Above you can see the following functions are used to log items based on a log, warn or info. It won’t cause errors when the console isn’t available. The following functions work in Google Chrome console −console.log( ); console.warn(); console.error();The Console object is used to access the browser's debugging console. As an example, consider the Web Console ... Read More

How to set cookies to expire in 30 minutes in JavaScript?

Prabhas
Updated on 09-Jan-2020 08:07:48

6K+ Views

You can extend the life of a cookie beyond the current browser session by setting an expiration date and saving the expiry date within the cookie. This can be done by setting the ‘expires’ attribute to a date and time.ExampleYou can try to run the following example to set cookies to expire in 30 minutesLive Demo                                                  Enter name:                    

How to print the content of JavaScript object?

Johar Ali
Updated on 16-Jun-2020 13:50:35

198 Views

To print content of JavaScript object, you can try to run the following code. Here, the object is created using the new keyword −ExampleLive Demo                          var dept = new Object();          dept.employee = "Amit";          dept.department = "Technical";          dept.technology ="C++";          document.getElementById("test").innerHTML =          dept.employee + " is working on " + dept.technology + " technology.";          

How to set cookies to expire in 1 hour in JavaScript?

seetha
Updated on 16-Jun-2020 11:47:42

8K+ Views

You can extend the life of a cookie beyond the current browser session by setting an expiration date and saving the expiry date within the cookie. This can be done by setting the ‘expires’ attribute to a date and time.ExampleYou can try to run the following example to set cookies to expire in 1 hour −                                                  Enter name:                    

How to clear all cookies with JavaScript?

Shubham Vora
Updated on 23-Aug-2022 09:49:46

18K+ Views

In this tutorial, we will learn to clear all cookies using JavaScript. The cookies are the text or data stored in the format of text files in the browser or user's computer, and it is one kind of cache memory. The developer can store the username, authentication tokens, etc., in the browser's cookies. When a user visits the webpage for the first time, it retrieves the user information from the server and stores it in the cookie format in the browser. After that, when a user visits the webpage again, it retrieves the required data from cookies instead of the ... Read More

How to set cookies expiry date in JavaScript?

radhakrishna
Updated on 16-Jun-2020 11:46:10

5K+ Views

Extend the life of a cookie beyond the current browser session by setting an expiration date and saving the expiry date within the cookie. This can be done by setting the ‘expires’ attribute to a date and time.ExampleYou can try to run the following example to set the expiry date of a cookie by 1 Month −                                                  Enter name:                    

How to create cookies in JavaScript?

Rishi Rathor
Updated on 16-Jun-2020 11:51:30

654 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, commas, or whitespace. For this reason, you may want to ... Read More

How does JavaScript .prototype work?

Shubham Vora
Updated on 22-Jul-2022 13:01:53

251 Views

In this example, we will learn how the prototype works in JavaScript. It is rare if a JavaScript developer doesn’t use the objects while developing the functions, and the objects can make a lot of work easy for developers.The prototype is also the advanced concept associated with the objects in JavaScript. Many of you have heard about the prototypes for the first time but don’t worry. We will cover all things about the prototypes in this tutorial.What does the prototype do?The prototype is the object created for every function class when the program starts execution. However, it depends on the ... Read More

Advertisements