PART III: STRENGTHENING THE WARRIOR'S ARSENAL
3.1 Taking an inventory of what we’ve learned
Give me 5 minutes and I’ll tell you everything I know!
Sometimes it feels like that, right?
Well, we have covered quite a lot:
We have seen how a data structure such as an array acts as a numerically indexed list of items, and how to use the for loop to traverse (scan) the array and manipulate each one of its elements based on the array.length property.
We have used push() and unshift() to insert new items into an array, and pop() and shift() to remove items from the array.
We have also experimented with splice() to remove, replace or add new items into any specific location of an array, and how we can copy a whole section of the array into another array by using slice().
What about sorting arrays with sort()? And how to use join() to convert an array into a string.
Last but not least, we have seen how indexOf() can be useful to find the location number of a certain item, or to check if the item has already been inserted in the array.
So much we’ve learned in such a short time!
What about objects?
The items in an object, which are called properties, can be addressed by either dot syntax or by bracket syntax. Some of the properties are called methods because they represent functionality and functionality involves at least one function mechanism.
The for in loop is a variation of a for loop specifically created to traverse over objects. The temporary counter variable serves to dynamically store the key names of each property so that we can manipulate the data, such as printing to screen.
We know that dot syntax does not work with dynamic representations of properties. Also when we print a list of properties, we can filter out the methods by creating a condition for output with a typeof verification.
In the process of learning all these we also learned about conditional statements by using if, else if, else.
Functions are mechanisms that save executable code. In a sense, a function does not hold a value, it holds a potential value that only materializes when we call the function. A function can have input parameters as temporary placeholders for data being passed into the function when the function is called. Of course we can also have functions that do not take any data, they just perform a certain task.
We know that the return mechanism is the only true raw output from a function and we need to catch this returned data if we want to reuse it somewhere else before it gets lost in cyberspace.
Another way to output data from a function is to internally reassign an outer variable, since functions have access to outer variables. As for console.log(), it is just a way to display data on the screen and always in a string type format.
And there you have it, close to 200 pages of fun in a nutshell.