Found 10483 Articles for Web Development

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

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

328 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

7K+ 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

262 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

10K+ 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

21K+ 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

788 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

388 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

How to turn a String into a JavaScript function call?

Smita Kapse
Updated on 03-Oct-2019 07:00:23

529 Views

To turn a string into a JavaScript function call, try to run the following codeExampleLive Demo                    function myFunction(argument) {             alert('My function ' + argument);          }          functionName = 'myFunction';          window[functionName]('is working.');          

Smart / self-overwriting / lazy getters in javaScript?

Shubham Vora
Updated on 15-Nov-2022 10:37:53

673 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. The getter helps when we need to get some dynamic value without an explicit call. Users can follow the syntax below to work with the getters. Syntax { get prop() {} } { get [exp]() {} } The prop and the exp are the object's properties that bind to a function. 'prop' is a simple object property, and 'exp' is an expression. ... Read More

Advertisements