JavaScript Learning Path – JavaScript Fundamentals

JavaScript Fundamentals by Liam McLennan

Note that this course was recorded in 2011 and therefore does not cover any of the new ES2015 features. However learning the earlier version of the language is a good idea in my opinion. This one of the first Pluralsight courses I ever watched, which was back in 2012. At that time, I learned that I had a lot left to learn about this language. I enjoyed watching this course again today.

Introduction

Liam introduces by explaining that he will demonstrate that JavaScript can be a beautiful language. This course focuses on learning the language rather than specific things that you can do in the language.

JavaScript is inspired by three earlier languages: Java, Scheme, and Self.

Liam demonstrates Google Docs as an example of what can be achieved in the language. This course was recorded in 2011, and the latest version of JavaScript is now even more powerful.

Liam gives the early history (1995-2011) of JavaScript and ECMAScript, and then begins with Hello World using js bin. He also discusses js db, which has a REPL: read, enter, process, loop.

In 2016, js db still works fine, but Node is a more popular option for programming in a REPL, and Chrome has a decent one inside its dev tools.

Building Blocks

Beginning with comments, we learn how to do both single and multi line versions.
Variables should be declared using the var keyword.
Liam uses the typeof keyword for showing which primitive types a variable belongs to.

Two of these primitive types are null and undefined. Liam explains the difference between these. Null is the absence of a value, so you will generally only find it a variable has been explicitly set to null.

Liam recommends the Mozilla Developer JavaScript Guide for learning many details of the language. He shows how to use objects, and how equality works.

There are two types of equality checking operators in JavaScript: == and ===
There are many type coercion problems that you can run into with the == operator, so Liam’s examples use === and !== except to show
“” == 0 evaluates to true in JavaScript.

Functions

This module begins declaring functions and we learn that we can declare either named or anonymous functions. There are also immediately invoked functions and Liam explains the benefits of using these.

In the next clip on invoking functions, we see another demo showing JavaScript does not support function overloading (like C# does), and overwrites the first function definition when the same function name is used.

The arguments object behaves like an array but is of the type object.

Recursion means a function can call itself. This is a very useful feature but you must ensure that there is a definite reachable exit, otherwise the function we continue to run until the program is shut down or runs out of memory.

When a function is defined inside of another function, the inner function has access to the variables defined in the outer scope. Liam says this is a property known as a closure. Kyle’s YDKJS book contains a much more precise definition than this, but it Liam’s definition is okay for getting started with JavaScript.

Liam shows an example with an outer, middle and inner function.

Control Flow

Conditional Control Flow first explains blocks (i.e. what you see within the { } braces). It is important to understand that scoping works differently in JavaScript than in many other languages. This clip covers the if, if else, and switch statements:

Iteration explains the for loop and the for..in loop, which is similar to foreach in C#
It also explains the while loop and the do…while loop

Error Handling covers throwing and catching of exceptions and explains a try catch finally block.

Types and Libraries

If you have watched Scott’s introductory course, you will already have come across most of the built-in types. This module will fortify that knowledge with additional information.

String is a type that should be familiar already. Liam explains the common string escape sequences with an example using JS bin including outputting Unicode symbols.

String Methods begins with string concatenation (using the + operator) , then charAt, indexOf, replace and many others are mentioned and demonstrated with examples.

Number – JavaScript only has one number type which is a floating point number. Liam explains these numbers are not exact and shows more examples including adding and multiplying numbers, and toFixed. Working with whole numbers is a good idea when you can’t afford to lose accuracy.

Arrays are indexed collections and each element can be of any type. Liam provides many examples of working with arrays, including slice and splice functions.

Regular Expressions are a tool for string pattern matching. They are used for searching, replacing, and extracting parts of strings.
If you would like to learn more, see my article on Learning Regular Expressions

Dates are an area of JavaScript that is fairly terrible. Months are zero based so new Date(2016, 02, 01) means 1st of March 2016 rather than 1st February 2016 as many developers would assume.

Liam demonstrates the .toUTCString function, which displays a date as a string in coordinated universal time. He also subtracts one date from another, which returns the number of milliseconds between the two dates. Then he talks a bit about the date JS library. If you are interested in using a JavaScript date time library, I also recommend taking a look atmoment JS.

eval and JSON – Liam states eval is slow, insecure and unnecessary and recommends NEVER using it. Kyle Simpson also talks about eval in his Advanced JavaScript course (on Pluralsight and Frontend masters) and goes into greater depth but has a similar overall opinion. Sometimes eval is pronounced as “evil”.

Liam shows some equivalent JSON and XML data side by side, and the difference is striking: JSON is much less verbose and much easier to read than XML. Parsing JSON data is a better alternative to using eval.

isNaN is a simple function taking one argument and returning true if the argument is NaN: not a number.
parseFloat is a function for converting a string into a number.

Liam covers five functions that are part of the math object: abs, floor, ceil, low, random

Firebug

Firebug is a developer tool add-on for Firefox. At the time when this course was recorded, it was an essential tool for Web developers. However in the last 5 years browsers have come on a long way. If you are interested in gaining an in depth understanding of debugging on the web, here are a couple of alternatives:

Shawn Wildermuth has a course called debugging the web with firebug, webdeveloper and fiddler
John Sonmez has a course called Using the Chrome developer tools

Testing

As with Scott’s course, its great to see another JavaScript beginner course covering unit testing. In this module, we cover a wider range of technology options: especially QUnit and Jasmine. QUnit is part of the jQuery project, and Liam says it is very good for testing DOM interactions.
Jasmine is a behaviour driven development testing framework and is the testing framework that I have used most often over the past 18 months.

Liam says that having tests in place is the only safety net available in JavaScript to protect the programmer against himself. There are also several additional reasons for unit testing which Liam explains.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s