Skip to main content
typo
Source Link
Ron Klein
  • 9.5k
  • 10
  • 59
  • 91

An approach using a try/catch

function getFormatedDategetFormattedDate(date = new Date()) { try { date.toISOString(); } catch (e) { date = new Date(); } return date; } console.log(getFormatedDategetFormattedDate()); console.log(getFormatedDategetFormattedDate('AAAA')); console.log(getFormatedDategetFormattedDate(new Date('AAAA'))); console.log(getFormatedDategetFormattedDate(new Date(2018, 2, 10)));

An approach using a try/catch

function getFormatedDate(date = new Date()) { try { date.toISOString(); } catch (e) { date = new Date(); } return date; } console.log(getFormatedDate()); console.log(getFormatedDate('AAAA')); console.log(getFormatedDate(new Date('AAAA'))); console.log(getFormatedDate(new Date(2018, 2, 10)));

An approach using a try/catch

function getFormattedDate(date = new Date()) { try { date.toISOString(); } catch (e) { date = new Date(); } return date; } console.log(getFormattedDate()); console.log(getFormattedDate('AAAA')); console.log(getFormattedDate(new Date('AAAA'))); console.log(getFormattedDate(new Date(2018, 2, 10)));

Source Link
codeKonami
  • 980
  • 9
  • 14

An approach using a try/catch

function getFormatedDate(date = new Date()) { try { date.toISOString(); } catch (e) { date = new Date(); } return date; } console.log(getFormatedDate()); console.log(getFormatedDate('AAAA')); console.log(getFormatedDate(new Date('AAAA'))); console.log(getFormatedDate(new Date(2018, 2, 10)));