Chapter 5: Functions

5.1 What is a Function?

Javascript FunctionsSo, what exactly is a function?

A function is a block of code that performs a certain task. For an analogy, think of the mathematical functions available in MS Excel. To add numbers, we can use the sum() function and type sum(A1:A5) instead of typing A1+A2+A3+A4+A5.

In Javascript, we can use one of the many built-in functions/methods to perform various tasks for us. Some of the methods that we’ve used so far include the prompt(), push() and sort() methods.

For a full list of all the built-in methods available in Javascript, check out this website:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Methods_Index