When you use Html5 localStorage values are stored as strings. This is something you need to deal with if you want to store the state of a checkbox and then restore it at a later date. I was hoping that something like this would work:
(function() {
function e(id) { return document.getElementById(id); }
e('save').addEventListener('click', function() {
localStorage['check-value'] = e('checkbox').checked
})
e('checkbox').checked = localStorage['check-value'];
})();
But it seems that ‘check-value’ will store something along the lines of "false" if the box is not checked and the string "false" gets type-coerced to true on that second-to-last line. I know that I could make a little if-test but this is for a hobby project and I want to figure it out if possible. Can "false" be coerced to false?
I’m not using libraries for this btw because its a chrome extension and I want to keep it lightweight.
“false” is just a string like any other, you would need to do your own check here.