Skip to content

Instantly share code, notes, and snippets.

@onelharrison
Last active January 27, 2018 16:19
Show Gist options
  • Save onelharrison/ac5d30620ce06154b3682baf7d2ad0da to your computer and use it in GitHub Desktop.
Save onelharrison/ac5d30620ce06154b3682baf7d2ad0da to your computer and use it in GitHub Desktop.
Code snippet showing the behavior of passing undefined to the moment function.
// ................................
// behavior in moment.js v2.x.x
// ................................
const momentWithUndefinedArg = moment(undefined);
const momentWithNoArgs = moment();
// expected result
momentWithNoArgs.isValid(); // true
momentWithNoArgs.format("YYYY-MM-DD"); // today's date
// undexpected result
momentWithUndefinedArg.isValid(); // true
momentWithUndefinedArg.format("YYYY-MM-DD"); // today's date
momentWithUndefinedArg.isSame(momentWithNoArgs); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment