I’ve just been wondering are local (declared inside of functions) variables more efficient to use than public variables? I’m using Javascript.
It really depends on what you’re doing.
If performance isn’t a big issue, write code that’s easiest to maintain.
If performance is a big issue, write it both ways and test it in your usage scenario. There are no generic answers for this kind of thing.
Local variables are slightly faster, however you should be using them where possible regardless because it’s generally better code design.
–Eric