Categories
JavaScript Answers

How to set boolean values in LocalStorage with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.