db.collection.findOne
is an async operation (MongoDB, but that doesn't really matter here), which is why I'm wrapping it in a promise here.
var letsDoSomething = new Promise(function(resolve, reject){
db.collection('stackoverflow').findOne({question: true}, function(err, question){
resolve(question); // let's pretend we found a question here, and it is now resolving
})
})
letsDoSomething.then(function(myData){ // it resolves
console.log('foo', bar); // since 'bar' is undefined, this should fail – why doesn't it? No error messages, it goes completely silent
});
Why doesn't the debugger throw an error when I try to log bar
, which simply doesn't exist? It just goes poof silent, not a word.
Expected result (in my mind):
console.log('foo', bar);
ReferenceError: bar is not defined
What am I missing?
Environment:
node -v
v0.12.4