September 2015
Intermediate to advanced
92 pages
1h 30m
English
CHAPTER 12
![]()
Cookies
A cookie is a piece of data sent from a web site and stored locally on the user’s computer. They provide a persistent storage space, allowing web sites to remember users as they move between pages or return to the site.
Creating Cookies
Cookies are created by assigning a name-value pair to the document.cookie object. They are limited to storing string values only.
document.cookie = "cookie1=mycookie";
The same object is used for retrieving the cookie string.
console.log(document.cookie); // "cookie1=mycookie"
To modify a cookie, you just need to assign it a new value. This will overwrite the previous cookie.
document.cookie ...Read now
Unlock full access