Control Flow and Functions
Control flow is the order in which your computer executes the script written in your code. Reminder, it is important to remember that you not only read from the start to the bottom of the document but also program structures can impact the oder of program executions.
We can’t get too into control flow without discussing what are functions and how do they help our website evolve into the smooth operator we are looking for. Functions, simple put, is a set of specific instructions written once in a Javascript document that can be repeatedly activated, without having to rewrite the entire set of instructions.
Formatting for functions can be a little overwhelming if you have no experience with them, but once you learn to read the syntax they are just as easy to understand as any other code.
functionName (any , parameters , needed) {
code to be executed;
more code to be executed;
}
Then, any time you are interested in running this program within your document you can simply Invoke ik Having this section of code written once near the top of the document makes it available to be “invoked” or called to execute throughout the document. This is done simply by writing
functionName()
Some quick reminders for function syntax, the code is not executed where it is written. The function must be invoked seperately. But you can have one function invoke another function and so on. You just need to have the function being executed invoked in a different section of your code.
Click Here to return home