JavaScript Types of Functions
"Rocky" Hiroki Ueno

"Rocky" Hiroki Ueno @rockyueno0223

About: Learning Web development in college to be an engineer From Japan🇯🇵 Now in Canada🇨🇦

Location:
Vancouver, BC
Joined:
May 2, 2024

JavaScript Types of Functions

Publish Date: Jun 28 '24
0 0

Named function (Function declaration)

function helloWorld() {
   console.log('Hello World');
}

helloWorld();
Enter fullscreen mode Exit fullscreen mode

Named functions are used when the codes need to be executed several times.

Anonymous function

let helloWorld = function () {
   console.log('Hello World');
}

console.log(helloWorld);
Enter fullscreen mode Exit fullscreen mode

Anonymous functions are used the codes needs to be executed only once or twice and also used in event handler as below:

.onclick = function() {
   console.log('Hello World')
}
Enter fullscreen mode Exit fullscreen mode

Arrow function

const helloWorld = () => 'Hello World';

console.log(helloWorld);
Enter fullscreen mode Exit fullscreen mode

Arrow functions are shorter ways of function expressions from ES6 and useful to write functions in short ways.

Comments 0 total

    Add comment