title: Uncaught TypeError: Cannot read property 'insert'
body: <p>Not able to find what is the wrong with the below code, let me know what is the issue...I am trying to construct the binary Search Tree and not able to construct.</p>
  
  <pre><code>function BinarySearchTree(){
    var Node = function(key){
      this.key = key;
      this.left = null;
      this.right = null;
    };
    var root = null;
  }
  //Inserting a Key into a tree
  
  this.insert = function(key){
    var newNode = new Node(key);
    if(root === null){
      root = newNode;
    }else{
      insertNode(root, newNode);
    }
  };
  
  var insertNode = function(node, newNode){
    if(newNode.key &lt; node.key){
      if(node.left === null){
        node.left = newNode;
      }else{
        insertNode(node.left, newNode);
      }
    }else{
      if(node.right === null){
        node.right = newNode;
      }else{
        insertNode(node.right, newNode);
      }
    }
  };
  
  
  var tree = BinarySearchTree();
  tree.insert(11);
  </code></pre>