DEV Community

loading...
Cover image for JavaScript Interview Question #21: ISO Date

JavaScript Interview Question #21: ISO Date

Coderslang: Become a Software Engineer
Teaching you to code at js.coderslang.com - JavaScript, HTML, CSS, Node.js, React.js, React Native
Originally published at learn.coderslang.com on ・1 min read

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)