Taking an inventory of what we’ve learned - STRENGTHENING THE WARRIOR'S ARSENAL - JavaScript in Plain Language (2015)

JavaScript in Plain Language (2015)

PART III: STRENGTHENING THE WARRIOR'S ARSENAL

JavaScript is an instrument that needs to be played.

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:

The purpose of variables; The type of data assigned to variables; How we introduce a variable name to JavaScript by prefixing it with var; How a simple variable data known as a primitive value is stored in the same location as its variable name, as opposed to complex variables known asreference variables, which are stored on a separate memory location than the variable name that points to them...

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?

We know that almost everything in JavaScript is an object of some sort, but normally we refer to objects when we talk about unordered lists, those lists indexed by key labels.

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.

Boolean true and false were introduced and we learned that, in JavaScript, every value is considered true except Boolean false, number zero, or the values undefined and null.

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.