How to add session-only cookies with JavaScript?

Spread the love

To add session-only cookies with JavaScript, we use session storage.

For instance, we write

const myVariable = "Hello World";

sessionStorage["myVariable"] = myVariable;

const readValue = sessionStorage["myVariable"];
console.log(readValue);

to add an entry with key myVariable into session storage with

sessionStorage["myVariable"] = myVariable;

We read the value in session storage with key myVariable with

const readValue = sessionStorage["myVariable"];

Leave a Reply

Your email address will not be published. Required fields are marked *