Creating functions in JavaScript - Part 3

Chinwendu Agbaetuo - Apr 12 - - Dev Community

Create a function that prints the current date and time using function declaration, function expression, and arrow function.

Function declaration

function getDate () {
  console.log(new Date());
};

getDate();
Enter fullscreen mode Exit fullscreen mode

Arrow function

const getDate = () => { console.log(new Date)};

getDate();
Enter fullscreen mode Exit fullscreen mode

Function expression

const getDate = function () {
  console.log(new Date());
};

getDate();
Enter fullscreen mode Exit fullscreen mode
> Fri Apr 12 2024 10:44:38 GMT+0100 (West Africa Standard Time)
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . .