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"];