Acknowledged, @bobince. According to the official documentation, it is recommended to utilize Date.toUTCString()
for setting cookie expiration dates.
I am confident that specifying an expiration date when creating a cookie crumb is crucial if you intend to enforce its removal at a later time. An implicitly generated cookie crumb without a specified expiration date defaults to being a session cookie (crumb), which means it persists until the browser is closed. I have attempted to expire a session cookie in the past without success.
If you opt to set an expiration date for the cookie crumb initially, bear in mind that you have the flexibility to use a variable for the new expiration date.
// assuming a non-session cookie crumb named "someCrumbName" already exists:
var now = new Date();
var expirationDate = new Date();
var someValue = "foo";
// setting the expiration date to a week earlier and removing the cookie
expirationDate.setDate(now.getDate() - 7);
document.cookie = "someCrumbName=" + someValue + ";expires=" + expirationDate.toUTCString();