title: Using a global variable to prevent code executing repeatedly unnecessarily
body: <p><strong>TL;DR:</strong> Is it bad practice to use a global variable to prevent code executing unnecessarily, and if so what are the alternatives?</p>
  
  <p>I have an Electron application that reads a stream of real time data from another application and outputs some elements of it on screen. </p>
  
  <p>There are two types of data received, real time (telemetry) data of what is currently going on and more static data that updated every few seconds (sessionInfo).</p>
  
  <p>The first time a sessionInfo packet is received I need to position and size some of the UI elements according to some of the data in it. This data will definitely not change during the course of the application being used, so I do not want the calculations based on it to be executed more than once*.
  I need to listen for all sessionInfo packets, there are other things I do with them when received, it is just this specific part of the data that only needs to be considered once. </p>
  
  <p><strong>Given the above, is this a scenario where it would be appropriate to use a global variable to store this information (or even just a flag to say that this info had been processed) and use this to prevent the code executing multiple times?</strong> All my reading suggests that Global Variables are never a good idea, but short of allowing this code to execute repeatedly I am unsure what alternatives I have here.</p>
  
  <p>*<em>I recognise that allowing this would probably make no practical difference to my application, but this is a learning experience for me as well as producing something useful so I would like to understand the 'right' approach rather than just bodge something inefficient together and make it work.</em> </p>