R
Reactiflux

✅ – Liil' Boo – 08-41 Aug 10

✅ – Liil' Boo – 08-41 Aug 10

LBLiil' Boo8/10/2022
Hey Would something bad happen (or nothing), if I try to do
JSON.parse(thing)
JSON.parse(thing)
and 'thing' is not an object or array ? Or does that change nothing ? !title <JSON.parse question>
UUUnknown User8/10/2022
Message Not Public
Sign In & Join Server To View
UUUnknown User8/10/2022
Message Not Public
Sign In & Join Server To View
LBLiil' Boo8/10/2022
Could be anything else What i'm really trying to is
JSON.parse(window.LocalStorage.getItem('key')
JSON.parse(window.LocalStorage.getItem('key')
And I want to be sure how to catch error And if it always returns a string Documentation didn't help me figure it out Or I didn't understand
UUUnknown User8/10/2022
Message Not Public
Sign In & Join Server To View
LBLiil' Boo8/10/2022
Wait, what If I stringify everything before set to Local Storage ? Then I would always deal with strings, right ? As such
window.localStorage.setItem('key', JSON.stringy(value)
window.localStorage.setItem('key', JSON.stringy(value)
UUUnknown User8/10/2022
Message Not Public
Sign In & Join Server To View
LBLiil' Boo8/10/2022
It's purely theoritical, I'm not coding (Sorry I should have mentioned it) Well, thank you for your time I go with the approach of stringify-ing everything
Mmarz8/10/2022
either way localstorage can only store strings
UUUnknown User8/10/2022
Message Not Public
Sign In & Join Server To View
LBLiil' Boo8/10/2022
I guess so, But documentation doesn't say what happens if I try
localStorage.setItem('key', true)
localStorage.setItem('key', true)
Would it become the string 'true' ? Or throw an Error
UUUnknown User8/10/2022
Message Not Public
Sign In & Join Server To View
LBLiil' Boo8/10/2022
As a string ? So localStorage can store booleans ? 😮
EEva8/10/2022
It'll stringify it yes
UUUnknown User8/10/2022
3 Messages Not Public
Sign In & Join Server To View
LBLiil' Boo8/10/2022
Thanks for confirmation
EEva8/10/2022
As if you set .setItem('... ', {}); it'll just stringify it into [object Object]
LBLiil' Boo8/10/2022
window.localStorage.setItem('key', JSON.stringy(value) 
window.localStorage.setItem('key', JSON.stringy(value) 
I'll stick to this approach, stringying everything, I'll think about accuracy* later Thanks timo, thanks Eva
UUUnknown User8/10/2022
3 Messages Not Public
Sign In & Join Server To View
LBLiil' Boo8/10/2022
I thought JSON.stringify would be harmless on things that are already a string
UUUnknown User8/10/2022
Message Not Public
Sign In & Join Server To View
LBLiil' Boo8/10/2022
That's bad?
UUUnknown User8/10/2022
Message Not Public
Sign In & Join Server To View
LBLiil' Boo8/10/2022
Well, better safe than sorry I'll go with your advice, dear stranger Thanks again
UUUnknown User8/10/2022
Message Not Public
Sign In & Join Server To View
LBLiil' Boo8/10/2022
!close
UUUnknown User8/11/2022
Message Not Public
Sign In & Join Server To View

Looking for more? Join the community!

R
Reactiflux

✅ – Liil' Boo – 08-41 Aug 10

Join Server