Well if I used the export to file approach to make it global I’d put access to that file behind some kind of getter function to try to keep it from getting screwed up. I’d rather not store it in a single var and have to keep track of the adventures my variable has gone on and hope it didn’t take a wrong turn. 😜
Makes sense, however I believe reading a file is more expensive (performance) as compared to simply passing around a variable. You can declare the variable using const. This will prevent it from ever being modified
That isn’t true. Const means you cannot reassign it, but you can change the value it is assigned to. It also doesn’t protect a variable outside of its own block scope. Scroll to “Not real constant “ section, it’s important to understand.
Well if I used the export to file approach to make it global I’d put access to that file behind some kind of getter function to try to keep it from getting screwed up. I’d rather not store it in a single var and have to keep track of the adventures my variable has gone on and hope it didn’t take a wrong turn. 😜
Makes sense, however I believe reading a file is more expensive (performance) as compared to simply passing around a variable. You can declare the variable using const. This will prevent it from ever being modified
That isn’t true. Const means you cannot reassign it, but you can change the value it is assigned to. It also doesn’t protect a variable outside of its own block scope. Scroll to “Not real constant “ section, it’s important to understand.
w3schools.com/js/js_const.asp
Thanks for sharing the link! I think I had a misunderstanding of the way const works.
I think I found a solution. You can do this in a function:
localStorage.setItem('NameOfThing', JSON.stringify(yourJSON);
then in another function/scope you can call that so:
let VarNameForThing = JSON.parse(localStorage.getItem('NameOfThing');
that moves the object to wherever you need it. I don't know if its a bad idea for some reason but it seems to work for basic stuff at least.