Search code examples
javascriptstringparseint

return value in localStorage as an Int in js?


I understand that localStorage only stores strings, but lets say the string is '43', would there be a way of printing this as an int?

I tried parseInt() but I keep getting NaN..


Solution

  • You should probably use isNaN() function to determine whether a value is an illegal number (Not-a-Number). If it is a number, you can pass it into parseInt(). Please let me know if you have other issues.