title: How exactly does document.cookie work?
body: <p>If I get Chrome to show me <code>document.cookie</code> by going into the console and typing <code>document.cookie;</code> it'll give me, say:</p>
  
  <p><code>"name=John; gender=male";</code></p>
  
  <p>But then if I type in, say, <code>document.cookie = 5;</code> all it does is add <code>5;</code> to the start of the string, so I get:</p>
  
  <p><code>"5; name=John; gender=male";</code></p>
  
  <p>If I try <code>document.cookie = null;</code> then it doesn't even do anything.</p>
  
  <p>How can this be? It's a variable, isn't it? So why isn't the assignment operator working the way it should? Is it actually just a bit of syntactic sugar rather than a real variable? And if so, what precisely is the sugar covering up?</p>