title: Javascript (Electron) 'TypeError: Cannot set property 'checked' of undefined'
body: <p>I am creating a tray application with Electron but I can't figure out why this wouldn't work. I am very new to JavaScript. I looked through answers on here but most of them don't work/are confusing to me.</p>
  <p>Basically, what I want the application to do is load settings from <code>electron-store</code> into the application on launch. However, once it reaches the <code>if</code> statement, it throws an error.</p>
  <p>This is the only code I have so far:</p>
  <pre class="lang-js prettyprint-override"><code>const path = require('path')
  const { app, Menu, Tray } = require('electron');
  const Store = require('electron-store');
  
  const store = new Store();
  
  let tray = null;
  
  function setDefaultStore() {
      if (!store.has('theme')) {
          store.set('theme', 'dark');
      }
  
      if (!store.has('style')) {
          store.set('style', 'colourful');
      }
  }
  
  function run() {
      setDefaultStore()
  
      tray = new Tray(path.join(__dirname, 'images/trayIcon.png'))
  
      const contextMenu = Menu.buildFromTemplate([
          {
              label: 'Theme', submenu: [
                  {
                      label: 'Platinum (light)',
                      type: 'radio',
                      checked: false,
                      click() {
                          store.set('theme', 'light');
                      }
                  },
                  {
                      label: 'Graphite (dark)',
                      type: 'radio',
                      checked: true,
                      click() {
                          store.set('theme', 'dark');
                      }
                  },
              ]
          },
          {
              label: 'Style', submenu: [
                  {
                      label: 'Colourful',
                      type: 'radio',
                      checked: true,
                      click() {
                          store.set('style', 'colourful');
                      }
                  },
                  {
                      label: 'Mono',
                      type: 'radio',
                      checked: false,
                      click() {
                          store.set('style', 'mono');
                      }
                  },
              ]
          },
          {
              type: 'separator'
          },
          {
              label: 'Update'
          },
          {
              type: 'separator'
          },
          {
              label: 'Quit',
              click() {
                  app.quit();
              }
          }
      ])
  
      if (store.get('theme') == 'light') { // Throws error here!
          contextMenu.items[1].submenu[1].checked = true;
          contextMenu.items[1].submenu[2].checked = false;
      } else if (store.get('theme') == 'dark') {
          contextMenu.items[1].submenu[1].checked = false;
          contextMenu.items[1].submenu[2].checked = true;
      }
      
      if (store.get('style') == 'colourful') {
          contextMenu.items[2].submenu[1].checked = true;
          contextMenu.items[2].submenu[2].checked = false;
      } else if (store.get('style') == 'mono') {
          contextMenu.items[2].submenu[1].checked = false;
          contextMenu.items[2].submenu[2].checked = true;
      }
  
      tray.setToolTip('Vanilla Auto');
      tray.setContextMenu(contextMenu);
  }
  
  app.on('ready', run);
  </code></pre>
  <p>Error:</p>
  <pre><code>TypeError: Cannot set property 'checked' of undefined
  </code></pre>