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?
Moment version 2.13.0
There is a static method .isMoment:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With