title: Anyone can explain to me document.cookie
body: <p>I found this code in w3schoool JavaScript cookie section, which is to read the cookie:</p>
  
  <pre><code>function getCookie(c_name)
  {
    if (document.cookie.length&gt;0)
    {
      c_start = document.cookie.indexOf(c_name + "=");
      if (c_start!=-1)
      {
        c_start = c_start + c_name.length+1;
        c_end = document.cookie.indexOf(";",c_start);
        if (c_end==-1) c_end = document.cookie.length;
        return unescape(document.cookie.substring(c_start,c_end));
      }
    }
    return "";
  }
  </code></pre>
  
  <p>In this line:</p>
  
  <pre><code>if (document.cookie.length &gt; 0)
  </code></pre>
  
  <p>what <code>document.cookie.length</code> means?</p>
  
  <p>In this line:</p>
  
  <pre><code>c_start = document.cookie.indexOf(c_name + "=");
  </code></pre>
  
  <p>why I need to add <code>=</code> after the <code>c_name(cookie name)</code>?</p>
  
  <p>In this line:</p>
  
  <pre><code>c_start = c_start + c_name.length+1;
  </code></pre>
  
  <p>why I need to add <code>c_name.length+1</code>? What the purpose?</p>
  
  <p>And what the meaning of this line:</p>
  
  <pre><code>  if (c_end==-1) c_end = document.cookie.length;
  </code></pre>
  
  <p>Can Anyone answer my question? Thanks!!!</p>