To set boolean values in LocalStorage with JavaScript, we can parse the string value into a boolean with JSON.parse
.
For instance, we write
const value = "true";
console.log(JSON.parse(value) === true);
to parse 'true'
back into true
with JSON.parse
.
Then the console log should log true
since the left side returns true
.