Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Is it possible to store integer value in localStorage like in Javascript objects and extract it without typecasting? without wasting too much if your time.
The question is published on by Tutorial Guruji team.
The question is published on by Tutorial Guruji team.
When I assign integer value to localStorage item
localStorage.setItem('a',1)
and check its type
typeof(localStorage.a) "string"
it returns string, I can typecast it to int for my use
parseInt(localStorage.a)
My question is it possible to store integer value inside localStorage as I can do for Javascript objects without typecasting?
a={}; a.number=1; typeof(a.number) "number"
Answer
My question is it possible to store integer value inside localStorage as I can do for Javascript objects without typecasting?
No.
Storage objects are simple key-value stores, similar to objects, but they stay intact through page loads. The keys can be strings or integers, but the values are always strings. [source]
We are here to answer your question about Is it possible to store integer value in localStorage like in Javascript objects and extract it without typecasting? - If you find the proper solution, please don't forgot to share this with your team members.