Array and Function Summary Array An array is a special type of variable It can hold more than one value at a time Can hold many values under a single name and uses loops to find a specific value An array literal is the easiest way to create an array e.g. var array-name= [item1, item2, item3…]; When referring to an array element you refer to the index number You can have different objects in one array… also functions in an array and arrays in an array Arrays are a special type of object Arrays use numbers to access its elements Objects use names to access its members Arrays use numbered indexes whereas objects use named indexes Built in array properties Length property- returns the length of an array which is the number of array elements contained The easiest way to add a new element to an array is using the push method Looping array elements Using a ‘for loop’ is the best way to loop through an array Function Is a block of code designed to perform a particular task Is executed when something invokes it (calls it) It is defined with the function keyword, followed by a name, followed by () Function names can contain letters, digits, underscores and dollar signs The code to be executed by the function is placed inside {} Function parameters are the names listed in the function definition Function arguments are the real values received by the function when it is called Function invocation Function ‘calling’ the code inside the function will execute when something calls the function Happens when an event occurs e.g. user clicks a button Function return When JavaScript reaches return statement, the function will stop executing If the function was called from a statement, JS will return to execute the code Functions often compute a return value