EdgeCoders
Published in

EdgeCoders

The different ways to define a function in JavaScript

So you want to create a function in JavaScript?

You. Have. Options:

1 — Declaration Function

function sum(a, b) { return a + b; } 

2 — Expression Function

// Can be named:
(function sum(a, b) { return a + b; });
// Or anonymous (AVOID)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Samer Buna

Samer Buna

26K Followers

Author for Pluralsight, O'Reilly, Manning, and LinkedIn Learning. Curator of jsComplete.com