The below example shows how to create and read later the cookie for the user name and age.
From the above you’ll see that the example is creating the cookie in this way:
document.cookie = "key1=value1;key2=value2;
And to read the cookies associated with the current document:
allCookies = document.cookie;
allCookies is a string that contains a semicolon-separated list of cookies. You can split this semicolon-separated string to get the individual cookies.
Something Talk About Cookies
In a simple scenario the web server instruct to client’s browser to write the some data in the form of a cookie. The browser writes that data in key value pair. If the browser writes cookies successfully than each time when the client arrives at another page on your site, the browser sends that stored cookie to the server with the request. So that on the Web Server you can read that cookie.