title: Why does Node think this isn't a function but javascript is fine sometimes?
body: <p>I have a larger project I'm working on that's calling a Lambda in AWS via an API Gateway that I've configured. In the Lambda I'm trying to dynamically call a variable based on a query string param on an API request by using the following:</p>
  
  <pre><code>var functionToCall = event.queryStringParameters.tech;
  console.log("functionToCall is " + functionToCall);
  global[functionToCall](event, output);
  </code></pre>
  
  <p>Unfortunately I get an error of</p>
  
  <pre><code>TypeError: global[functionToCall] is not a function
  </code></pre>
  
  <p>I've rewritten this using window to demonstrate it online and depending on whether I run it in jsbin or jsfiddle I get different results. The following works in jsbin:</p>
  
  <pre><code>'use strict';
  var functionArray = ["one", "two", "three"];
  var randFunction = functionArray[Math.floor(Math.random() * functionArray.length)];
  
  function one() {
    console.log("function one called");
  };
  
  function two() {
    console.log("function two called");
  };
  
  function three() {
    console.log("function three called");
  };
  
  console.log(randFunction);
  window[randFunction]();
  </code></pre>
  
  <p>When I run it in jsfiddle I get </p>
  
  <pre><code>Uncaught TypeError: window[randFunction] is not a function
      at window.onload (VM99:49)
  </code></pre>
  
  <p>Ultimately I'm looking for some help in running this in my Lambda(node.js) as it'll make things easier and also help me be DRY.</p>
  
  <p>Thanks!</p>