CO3404 Distributed Systems
CO3404 Lecture 3 - REST & Intro to NodeJS
Lecture Documents¶
Written Notes¶
Mistaken Proceeding
I am aware the numbers for the note pages are wrong.




Learning Objectives¶
- Write named functions, anonymous functions, and arrow functions.
- Write a function that takes another function as a callback parameter.
- Write an anonymous function as a function argument.
- Call an asynchronous asynchronous API functions such setTimeout and fetch.
- Explain the basic operation of code that uses promises
- Create and test a sample node express API application
Function Declaration¶
Many ways to define / declare functions, somewhat due to various browser incompatibilities and some enhancements to the language as it has evolved.
For named functions, the function is moved to the top of the file by the parser if not in a block so it can be called before its declaration.
Function Expression¶
A function expression creates an anonymous function and effectively assigns its address to its assigned variable.
The assigned function has only the scope it was defined, which allows more control over clashing functions that share the same name from various libraries.
Reason for modern day usage
Typically these days, function expressions are used to provide better scope control, unless a named function is needed or more appropriate.