Published in


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)




jsComplete’s Medium Publication — jsComplete is a FREE software educational library focused on JavaScript, Node, React & GraphQL. It has video courses, books, articles, and interactive lessons.

Recommended from Medium

How to Create a Social Media App with React Native

Click Event in Chrome: Spooky stuff

Adding a filter feature

187. Repeated DNA Sequences

Level Up Your JavaScript Arrays With These Four Building-Block Functions

Step by Step of Web Application Development

How to center elements in CSS?


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

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

More from Medium

005: When Best Practices Break Down

The 5 Golden Rules Of Code Reviews: An Essential Guide To Code Checking

Which are the best values that any Software Engineer should have?

What I enjoy the most as a software engineer at Compass — Tim Well Said