Search code examples
javascripthtmlcookieshttpcookie

What is the difference between key and value in html cookies?


What is the difference between key and value in html cookies?

i saw that a cookie looks like this in html request:

  not like this:
    Cookie: name1=key1; name2=key2;

  but rather like this:
   Cookie: key1=value1; key2=value2; 

and if a want to make a unique personal id for each cookie, say "UUID",

should i write key="UUID"? or value="UUID"?

im sorry for the "silly" question but im really confused here...

thank you!


Solution

  • a key-value pair is a way of storing information in an easily readable manner. You designate each piece of data (value) with a key, and reference the data with that key. So in your case, the string "UUID" would be the key, and the actual unique ID would be the value.

    uuid=4dh26532gf564836fgf597g36
    

    In your example, name1 would actually be the key, where key1 would be the value.

    In layman's terms, the key is what comes before the equal sign (=), and the value is what comes after it.