title: How to use dynamically created JavaScript object in a conditional statement?
body: <p>I'm having this little bump in a function, normally if the variable "receivedRDB" is undefined in the DOM, it is dynamically created in a form and if it is defined it takes the value of another variable "receivedR". But "receivedRDB" keeps being created, even when it is already defined in the DOM.</p>
  
  <pre><code>var receivedRDB = document.getElementsByName('receivedR')[0];
      if (typeof receivedRDB !== "undefined") {
  
          receivedR = JSON.parse(receivedRDB.value.split(",").slice(0));
  
      } else {
  
          receivedR = [];
  
  
      }
      if (typeof receivedRDB !== "undefined") { //never detected
          receivedR.push(toRemoveR);
          receivedRDB.value = JSON.stringify(receivedR).replace(/"\[\\|\\"]|\\"/g, "");
      } else { //problematic part
          event.preventDefault();
          receivedR.push(toRemoveR);
          var input = document.createElement("input");
          input.type = "hidden";
          input.name = "receivedR";
          input.value = JSON.stringify(receivedR);
          rForm.appendChild(input);
      }
  </code></pre>