TIMOTHY TOLLEY EDA

Starfish Raglan

JavaScript Basics

How does JavaScript compare to HTML and CSS?

HTML and CSS are the framework for the webpage. A Webpage without HTML is nothing and a Webpage with HTML but no CSS is merely plane text. A website without javascript integrated into it can be a perfectly functional website which serves its function, however, javascript is able to make the webpage come alive by interacting with the user and making changes in response to events. Javascript makes webpages interactive and helps the developer engage the user and communicate more effectively. Where HTML is directly linked to CSS by changing permanently to conform to the demands of the CSS code, javascript works alongside these other two forms of code to make changes to the complete structure.

Control flow and loops

Control flow is a method for writing code which helps guide the browser through certain steps (validated by success or failure) and give an particular output dependant upon the intial input. Looping is a form of control flow which loops back to the start of an array of code until a specific result is successfully reached. Loops repeat a certain set of code until the desired result is set forward. An example of this might be to set an alarm extra early for the next morning, wake up, check the time and press snooze and repeat this process several times until the final result of "get up" is reached when the input time reaches the last possible moment before being late.

Accessing data from arrays vs objects

An array is made up of a series of elements within square brackets separate by commas. Each of these elements can be accessed individually by calling upon the index which is attributed to it. In javascript arrays use zero-based indexing so therefore the first element is 0. To call an element of an array the array is called followed by the indice in square brackets eg. myArray[0]. In an object on the other hand each of the elements is made up of a 'property' and a 'value' separated by a colon. This is much like the metadata of a song on an album eg. name:xxx, release date:yyy, etc. These are accessed by calling the object followed by '.property'. This gives meaning to the value of each element by giving it a property description.

Functions

Functions are made up of sections of code which are initiated when said 'function' is called and with recognition of certain parameters. For example, when you put your washing machine on a gentle wash with the parameter that you want the water to be cold, the washing machine carries out a particular set of actions which wash your delicates safely and in this case with cold water. A function is useful as it can be called multiple times throughout a page of code without having to rewrite all the initial code. Functions are essential to effective writing of code as they reduce the room for error and save time and energy by not requiring code to be rewritten each time a parameter is changed.