Can someone explain to me why db is shown as undefined in the console given the following code:
function connect(){
   var db="Connected to";
  logConnection();
}
function logConnection(){
   console.log(db);   
}
connect();
This is obviously a simplified example but in reality I'm working with nodeJS and mongodb.  The db variable is in reality a connection to a database on which I want to perform queries.  If I can understand this in more detail, it would greatly help with my debugging.
 
     
    