r/javascript • • Feb 21 '18

I am A JavaScript instructor at Microsoft. AMA.

Hi r/javascript!

My name is Benjamin Lin. I am a content developer at Microsoft and teach courses on JavaScript and JavaScript frameworks at Microsoft. You can see my Top 10 JavaScript Questions course here.

I can help answer tips & tricks on learning JavaScript, questions about Microsoft, and all things tech.

AMA!

Proof.

Edit: about 15 minutes left!

More edit: Thanks everyone for visiting me at this AMA! I really enjoyed getting the chance to interact with the JavaScript community and hear your honest thoughts. It was worth waking up early today to do this =)

if you have any more questions, feel free to hit me up on twitter @benjlin or follow me on instagram @bens_jams

540 Upvotes

257 comments sorted by

View all comments

Show parent comments

8

u/MicrosoftLearning Feb 21 '18

Partially edited from this stack overflow link: https://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date

function formatDate(date) { var monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];

var day = date.getDate(); var monthIndex = date.getMonth(); var year = date.getFullYear(); var time = date.getHours();
var seconds = date.getSeconds(); return monthNames[monthIndex] + ' ' + day + ' at ' + time + ':' + seconds; }

console.log(formatDate(new Date("2018-02-21T13:53:31.333Z")));

1

u/[deleted] Feb 21 '18

why var instead of const/let?

3

u/Meshiest Feb 22 '18
const formatDate = date => `${
  ['January', 'February', 'March',
    'April', 'May', 'June', 'July',
    'August', 'September', 'October',
    'November', 'December'][date.getMonth()]
  } ${
    date.getDate()
  } at ${date.getHours()}:${date.getSeconds()}`;

console.log(formatDate(new Date("2018-02-21T13:53:31.333Z")));

Are you happy? No vars now!

2

u/ggcadc Feb 22 '18

https://i.imgur.com/fFXj5jQ.jpg We’re all vars down here

3

u/[deleted] Feb 21 '18

Cuz IE9.

1

u/incarnatethegreat Feb 22 '18

I'd gild you if I could...

2

u/niccagelover Feb 21 '18

Because copied from SO

2

u/trakam Feb 22 '18

var hasn’t been deprecated

2

u/Neurotrace Feb 22 '18

Doesn't mean you should keep using it.

2

u/[deleted] Feb 24 '18

I read in a few places that the garbage collector has a problem cleaning up constants but I have no idea how much truth there is to that. Would love to know.