DEV Community

Discussion on: The complete guide to JavaScript functions

Collapse
 
joelnet profile image
JavaScript Joel • Edited

For a "complete guide" I would have liked to see exceptions, this, closures, arrow syntax, async, argument destructuring, default values, and even maybe partial application (bind/call/apply) to have been covered.

Collapse
 
fernandosavio profile image
Fernando Sávio

I don't see why Exceptions should be in a "Function - Complete Guide". Closure would fit, though...

Collapse
 
joelnet profile image
JavaScript Joel

There are two ways to exit a function, one is to return a value, the other is to throw an exception.

Exceptions are a (valid) type of output that a function can produce. When you document a function that you have created, let's say for a public library, you should document the argument (inputs) the return value (output) as well as the types of exceptions that may be thrown.

An example of this can be seen here: msdn.microsoft.com/en-us/library/y.... The Math.DivRem method has documented two possible results the function will produce, either a System.Int32 or a DivideByZeroException.

Function Diagram

If a programmer does not treat (and handle) exceptions as a possible (and valid) function result they are are putting themselves at risk of authoring buggy software.

Thread Thread
 
fernandosavio profile image
Fernando Sávio

Good point man.
I surrender :D

Collapse
 
booligoosh profile image
Ethan

I will cover ES6 stuff in another article :D