Control Flow
Something to consider when programming with Javascript is control flow. You may be asking yourself, well what is control flow? Control flow is kind of like the order of operations you saw back in school, but for computers. Commands and processes are the same as how you tell your body to stand and walk, first you think about walking and then you tell your body to do or say certain things. Control flow acts in the same way in that things will happen in the order flow that you as the developer assign them to. As powerful as computers are you can’t just tell it you want a donut and expect it to magically produce a donut. You’d have to go through the ordered steps of turning the computer on, logging in, going to a website, and ordering the donut. Control flow works in the same way that it goes step by step when running programs and executing functions.
Functions
Speaking of functions, let’s talk a little bit more about what those are. Functions are a handy way of calling on multiple tasks to be done simply by calling a general term. For example if you tell your child to wash the dishes, it encomposses the preknown consideration that ALL dishes will be washed, not just the cups and not just the plates. So for example a function in coding may be labeled as washDishes and inside it’s expression of tasks is wash plates, wash cups, wash silverware. So instead of telling your child to wash each individual dish over and over saying the same thing a thousand times, you get the convenience of just saying washDishes and all the dishes get washed.
Invoke or Calling a Function
Something to keep a note of, we’ve been using terms like calling a function or calling a task. However what does calling or invoking really mean? In lamens terms calling a function or invoking one is simply put to reference a general term in this sense a term that you as the developer has decided to run a set of instructions. Similar to the dishes example, when you tell a child to do the dishes you’re calling or invoking the list of instructions that goes with doing the dishes such as applying soap, and scrubbing with a sponge. It simply means to reference a pre-determined set of instructions. Defining a function does not execute it. Defining it names the function and specifies what to do when the function is called. Calling the function actually performs the specified actions with the indicated parameters.
Parameters
Always remember that no matter how good of a function you make, you need a list of parameters. Well what are parameters and how are they defined? Parameters are a list of do’s and don’ts in a sense. They set guidelines on if the function can take place. To define these parameters in a function is typically done using parenthesis (parameter1, parameter2). Using the dishes example, doDishes(haveSoap, haveWater). In this particular example, only if having soap and having water can the function of doDishes be completed, if either of the parameters are missing then the function won’t work. Just like you can’t wash dishes without soap and water.
Summary
Control Flow
Functions
Invoking or Calling function
Parameters