readCookie

readCookie Function

The readCookie function is used to retrieve the value of a client-side first-party cookie by its name.

Function Signature

this.readCookie(cookieName: string): string | null

Parameters

  • cookieName (string, required): The name of the cookie you want to read.


Return Value

  • If the cookie is found: Returns the cookie value as a string.

  • If the cookie is not found: Returns null.


Examples

Example 1: Read an existing cookie

function() {
  var val = this.readCookie("JTS-RW");
  return val; // Value of the cookie
}

This example returns the value stored in the cookie named JTS-RW.


Example 2: Read a non-existing cookie

function() {
  var val = this.readCookie("JTS-RW");
  return val; // null
}

This example attempts to read a cookie that does not exist. As a result, it returns null.

Last updated

Was this helpful?