The document.cookie is a strange object

As you saw earlier, document.cookie shows a special behavior. Instead of replacing all cookies, it updates the variable to the new cookie. This behavior is implemented by a document that is actually called a host object instead of a native object. Host objects have the power to do anything, as they don't need to follow the semantics for regular objects.

Host objects are actually the objects provided in a particular environment--in our case, the browser. When JavaScript runs on the server (Node.js), you do not have access to a document or window. That means they're host objects--that is, dependent on hosts and implemented by hosts (browsers).

In this case, document.cookie overrides the assignment operator ...

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.