I am just thinking about best solution for situation when you have to initialize some variable and the "if something" update it. What way should I use and why?
let someObj = {};
if(localStorage.getItem('someData')) {
someObj = JSON.parse(localStorage.getItem('someData'));
}
let someObj = {};
if(localStorage.getItem('someData')) someObj = JSON.parse(localStorage.getItem('someData'));
if(localStorage.getItem('someData')) {
someObj = JSON.parse(localStorage.getItem('someData'));
} else {
let someObj = {};
}
Or maybe some other propositions?
Aucun commentaire:
Enregistrer un commentaire