Programming With JavaScript
Functions
- Functions are one of the fundamental things in JavaScript. A function is similar to a procedure; a set up statements that performs a task or calculates input and return an output
- To use a function, define it somewhere in the scope from which you wish to call it
Defining functions
- A function definition consists of:
- the function keyword followed by:
- The name of the function
- A list of parameters to the function, enclosed in parentheses and separated by commas
- The JavaScript statements that define the function, enclosed in curly brackets
Control Flow
- The control flow is the order in which the computer executes statements in a script
- Code is run in order from the first line in the file to the last line, unless there are structures in place that change the control flow
- e.g. conditions and loops
- A typical script in JS includes many control structures:
- conditionals
- loops
- functions