title: Javascript local static variable
body: <p>Not sure I completely understand answers to similar questions that I found here, so trying to be absolutely sure:</p>
  
  <p>I would like to have a local variable in a function, initialized only once (similar to static variables in strongly-typed languages such as C, C++, etc).</p>
  
  <p>Of course, I could declare it globally, but it seems better practice to have it within the scope of that function, since it is not used anywhere else.</p>
  
  <p>Now, here is what I do:</p>
  
  <pre><code>function func(data) {
      func.PARAMS = [
          {"name": "from", "size": 160, "indexed": true},
          {"name": "input", "size": 256, "indexed": false},
          {"name": "output", "size": 256, "indexed": false},
      ];
      ...
  }
  </code></pre>
  
  <p>And my question is, will <code>func.PARAMS</code> indeed be initialized only once, or will it be initialized every time the function is called?</p>
  
  <p>According to some of the answers that I found (<a href="https://stackoverflow.com/a/1535650">this one</a> for example), I need to precede the initialization with something like:</p>
  
  <pre><code>if (typeof func.PARAMS == 'undefined')
  </code></pre>
  
  <p>This "supplemental" would be irrelevant in strongly-typed languages of course, so I just want to be sure that it is absolutely necessary in order to ensure "static behavior" (i.e., one-time initialization).</p>