I'm attempting to understand types in the JavaScript world. My page is using moment.js. I have a function that sometimes returns a moment() and other times, returns a string (it's legacy code gone wild).
My code kind of looks like this:
var now = getDate();
if (now instanceof moment) {
console.log('we have a moment.');
} else {
console.log('we have a string.');
}
function getDate() {
var result = null;
// Sometimes result will be a moment(), other times, result will be a string.
result = moment();
return result;
}
When I execute the code above, I never get we have a moment.. Even if I manually make set result = moment();. Why is that? Am I misunderstanding instanceof or moment?
