I'm working with a cookie, setting other code varibles using the value of the cookie.
I have defined data about the default state of the cookie as so:
const Cookie = {
config: {
name: 'Test_Cookie',
expire: 1,
value: true,
},
...
}
When criteria are met, the cookie gets set for the first time, using this.config.value
to set the value of the cookie to true
:
setCookie: function () {
if (!this.isCookieSet()) {
$.cookie(this.config.name, this.config.value, this.config.expire);
}
},
However, I am finding when I return the cookie value in the code I get "true"
back as a string rather than just true
. For example (name changed in above example for simplicity):
If I try to do a comparison on the value
of the cookie, and use === true
I get a false result. If I do === "true"
then I get a true result:
showStuff = $.cookie('Test_Cookie') === "true"; // showStuff = true;
OR
showStuff = $.cookie('Test_Cookie') === true; // showStuff = false;
Why does the variable type of the cookie value change when set?