javascript - Local Storage turns wrong or null value -


i'm trying set value in local storage. this:

if (localstorage) {      var event = localstorage.getitem("event");      if (event != "undefined" || event != "null") {         console.log(event)     } else {         localstorage.setitem("event", "event name");         console.log('test');     } } 

i can't save value in local storage first time. it's not returns in else condition. returns null exist check condition. can help?

if doesn't exist, null returned, not string "null", change to:

if (event != null) {     console.log(event) } else {     localstorage.setitem("event", "event name");     console.log('test'); } 

from w3 docs:

the getitem(key) method must return current value associated given key. if given key not exist in list associated object method must return null.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -