DEV Community

Cover image for JavaScript Interview Question #21: ISO Date
Coderslang: Become a Software Engineer
Coderslang: Become a Software Engineer

Posted on • Originally published at learn.coderslang.com on

JavaScript Interview Question #21: ISO Date

js-test-21

How does the ISO date look in JavaScript? What will be logged to the console?

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

In the first line, we create a new Date object.

It holds the current date and time.

The function toISOString returns the string representation of the date object in the ISO format. It starts with the year and ends with time. Something like 2020-12-27T10:35:26.159Z.

When we’re slicing this string with slice(0, 4) we’ll get the first four characters, which represent the year.


ANSWER: the current year will be logged to the console.

Learn Full Stack JavaScript

Discussion (0)