Found 6710 Articles for Javascript

How to print the content of JavaScript object?

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

261 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

787 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

386 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

527 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

How can I Execute JavaScript at the Command Prompt?

Shubham Vora
Updated on 27-Nov-2024 10:22:08

13K+ Views

To execute JavaScript at the command prompt, can be achieved through various methods depending on the environment. We will be discussing three different approach which can be used to execute JavaScript at the command prompt with stepwise explanation of steps. In this article, our task is to execute JavaScript at the command prompt. Different Methods to Run JavaScript at Terminal Here is a list of methods that can be used to execute JavaScript at the command prompt which we will be discussing in this article with stepwise explaination and complete example codes. Runnning JavaScript File ... Read More

How to concatenate several strings in JavaScript?

Ramu Prasad
Updated on 09-Jan-2020 07:13:47

272 Views

To concatenate several string, use “Array.join()” method. Here, we will concat the following strings:John Amit SachinExampleYou can try to run the following code to concat several stringsLive Demo                    var arr = ['Amit', 'John', 'Sachin'];          document.write(arr.join(', '));            

Advertisements