Since this is tagged "marklogic" I will provide a MarkLogic non-standards answer.
The standards based answer is 'no' or 'question out of scope' because XQuery doesnt define an 'application scope' ( beyond the excecution of a the top level module's statement -- which in some context could be called 'application scope' )
In MarkLogic there is a supported feature called 'Sessions';
For web applications that coresponds to what is usually called "Session".
Sessions are created by the first call to xdmp:login() (explicitly or implicitly by running in the HTTP Server using a supported authentication).
Session 'state' is created on the first write to a session field (explicitly via xdmp:set-session-field, or implicitly in some cases(*)).
https://docs.marklogic.com/xdmp:set-session-field
Session Fields are a map of name (xs:string) to item()*
They last as long as the session lasts (see notes on expiration in link above).
Note that Sessions that span multiple HTTP requests require that the client side participate via proper HTTP Cookie handling ( ML server has no ability nor attempts to to track requests after the socket is closed except via the HTTP Cookie mechanism.)
If you are using a modern browser you need to not disable cookies.
If you are using a modern Web Client library this will likely be done for you.
If you are using one MarkLogics published SDK's (java, node, xcc) it will be done for you.
If you are going through a load balancer, Level 3 router, gateway, proxy ... those may need to be configured for "HTTP Session Affinity" (based on the cookies) to guarantee that cookies are passed through unchanged and that the SessionID cookie is mapped to HTTP affinity.(**)
Note: IT devices vary greatly in their capabilities and terminology.
What is often called "Session Affinity" may not relate to cookies, or
the right cookies. These can often be configured to work correctly but may
require custom code or configurations.
(*) Session state can be created implicitly in some cases by creating a multi-statement transaction.
(**)
https://docs.marklogic.com/guide/node-dev/extensions