title: Initializing localStorage variables with Javascript doesn't work when in a function
body: <p>Okay, so I'm using the following if statements to preset certain variables of an application I'm making:</p>
  
  <pre><code>if(localStorage.s1 == undefined) {
      localStorage.s1= 50
  }
  if(localStorage.s2 == undefined) {
      localStorage.s2= 100
  }
  </code></pre>
  
  <p>And that works fine. There's about twelve of these presets, so I've re-factored it by using the following function: </p>
  
  <pre><code>function setterfunc(targetedelement, presetting) {
      if(localStorage.targetedelement == undefined) {
          localStorage.targetedelement = presetting;
      }
  }   
  </code></pre>
  
  <p>But when I call it with </p>
  
  <pre><code>setterfunc(foobar, 342)
  </code></pre>
  
  <p>Google Chrome console just tells me:</p>
  
  <pre><code>Uncaught ReferenceError: foobar is not defined 
  </code></pre>
  
  <p>Any help? The verbose way around of repeating the if statements works perfectly.</p>