This function does not put any cookie. It checks to see if a cookie already exists. The If statement asks if document.cookie. Yes, I know that the cookie does not reside in the document, but rather in a file in another part of the hard drive. That doesn't matter to JavaScript.
Cookie is a property and simply saying document.cookie fires up the process of looking for one.
For once, something that should be difficult is easy. We need to find out. Notice how we grabbed the cookie. We know that cookie is a property of document just as any form elements would be. That's why we get to use a hierarchy statement format when going after the cookie.