Dan Schnau dot com

LocalStorage, The unary operator and strict equality in JavaScript

My stance on JavaScript strict vs. type-converting comparison (double vs. triple-equals) is to always use strict equality. But the other day this tripped me up.

I had a number stored in local storage and I wanted to check it against a constant number.

But, the check failed even when the numbers were the same. I then learned that everything stored in local storage is stored as as string. your data).

I put the unary operator + in front of the value read out of local storage, and the problem was resolved.