GPEN · Question #401
Which of the following is the JavaScript variable used to store a cookie?
The correct answer is C. Document cookie. JavaScript accesses and manipulates browser cookies through the document.cookie property exposed by the Document Object Model.
Question
Which of the following is the JavaScript variable used to store a cookie?
Options
- ABrowsercookie
- BWindowcookie
- CDocument cookie
- DSession cookie
How the community answered
(62 responses)- A3% (2)
- B10% (6)
- C81% (50)
- D6% (4)
Why each option
JavaScript accesses and manipulates browser cookies through the document.cookie property exposed by the Document Object Model.
Browsercookie is not a valid property, object, or interface in any JavaScript specification or browser Web API.
Windowcookie is not a property of the window object or any other JavaScript built-in - it does not exist in the Web API.
In the browser's Document Object Model, document.cookie is the standard and only native JavaScript property used to read, create, update, and delete cookies for the current document. Reading document.cookie returns a semicolon-delimited string of all name-value cookie pairs in scope, and assigning a new string to it sets or updates an individual cookie, making it the correct JavaScript interface for all cookie operations.
Session cookie describes a category of cookie (one with no expiry date, deleted when the browser session ends), not a JavaScript variable or property used to access or store cookies.
Concept tested: JavaScript document.cookie DOM property for cookies
Source: https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie
Topics
Community Discussion
No community discussion yet for this question.