Deleting cookies

To delete a cookie, you return to the cookie and then specify an expiry date for it. After which, the browser will delete the cookie and no longer send it to the server on every request.

Here's how to implement that in code:

document.cookie = "myFirstCookie=good;"document.cookie = "mySecondCookie=great;"console.log(document.cookie);document.cookie = "mySecondCookie=; expires=Thu, 01 Jan 1970 00:00:00 GMT";console.log(document.cookie);

1 January 1970 00:00:00 is as far back in time as we can go, as JavaScript follows Unix's timestamp. The output for the preceding code is as follows:

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.