JavaScript

Last Updated: 4/13/2023

Cookies

Cookies are data, stored in small text files, on your computer. Cookies are saved in name-value pairs

When a web server has sent a web page to a browser, the connection is shut down, and the server forgets everything about the user. When a browser requests a web page from a server, cookies belonging to the page are added to the request. This way the server gets the necessary data to "remember" information about users.

document.cookie = "username=ganesh";
document.cookie = "email=ganesh@gmail.com";
let date = new Date(Date.now() + 86400e3);
date = date.toUTCString();
document.cookie = "username=ganesh; expires=" + date;

let x = document.cookie;

document.cookie = "username=ganesh; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/";

document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";