Is Document. Cookie Ever Undefined?

Is Document. Cookie Ever Undefined?

I'm just curious if document.cookie can ever return undefined.

I read quirksmode's article on cookies and I looked at "Is !document.cookie reliable?" but they don't explicitly answer this question.

Can document.cookie ever be undefined?

5

2 Answers

The document.cookie property is defined in DOM Level 2, and implemented in every major browser. It sets/gets a string, which may be an empty string (which is falsey, but not undefined).

No.

You can read the spec here

It throws an error if it's set to a value that doesn't adhere to the spec.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Chloe Bennett
Author

Chloe Bennett

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.