JavaScript Numbers and Dates - Exercise 1

It checks whether a value is a finite number without coercing other types.

javascript

Number.isFinite(42);

Use Number or a suitable parsing method.

javascript

const total = Number('19.5');

NaN represents a value that is not a valid number.

javascript

const result = Number('not a number');
console.log(Number.isNaN(result));

Math.floor returns the greatest integer less than or equal to the value.

javascript

Math.floor(4.9);

Math.random returns a value greater than or equal to zero and less than one.

javascript

const randomValue = Math.random();

It returns the current time as milliseconds since January 1, 1970 UTC.

javascript

const timestamp = Date.now();

Pass the string to the Date constructor.

javascript

const launchDate = new Date('2026-09-23T12:00:00Z');

Call getFullYear on the Date instance.

javascript

const year = launchDate.getFullYear();

Local Date methods use the environment's timezone, while UTC methods use UTC.

javascript

date.getHours();
date.getUTCHours();

Use toISOString for a UTC ISO 8601 representation.

javascript

const formatted = new Date().toISOString();