Learning JavaScript: Part 2: Data Types and Arrays

Learning JavaScript

JavaScript is an interpreted programming language commonly found in web browsers. First appearing in 1995, it has grown to be the de facto web programming language used in most websites and on many systems serving webpages.

Data Types and Arrays

Most programming languages have a concept of data types. These are various kinds of data and are usually handled differently.

Screenshot 2018-09-17 11.36.49

Consider, for example, the values 1 and “Hello, world!”. These are two different types of data and JavaScript understands them in separate ways.

Different Types of Numbers

Screenshot 2018-09-17 11.40.03

JavaScript understands different types of numbers. They can be integers or decimals. In JavaScript, these are all Numbers and can be used in calculations.

Letters and Numbers as Strings

Screenshot 2018-09-17 11.45.54

Many programming languages, like JavaScript, understand letters, numbers, and other entries within single or double-quotations as strings.

In JavaScript, a String is a special data type that comes with some built-in abilities. They are understood as one unit and are changed using special JavaScript functionality.

The are often useful when some task needs to use text instead of numerical values.

Arrays as a Sequence of Values

Screenshot 2018-09-17 11.53.32

JavaScript uses a third type of data called an array. While not a number or collection of letters and number within quotations, an array can be thought of a sequence of values. The type of these values does not matter. In JavaScript, an array is simply a series of values separated by commas.

Screenshot 2018-09-17 12.02.04

Arrays can also be inside other arrays. In these cases, the array is said to be multidimensional. Instead of being a sequence of values, a single dimension, it can have its own arrays that make it have extra dimensions.

Screenshot 2018-09-17 12.08.38

Arrays are called sequences of values because their position can be referenced. Much like a book, an entry in an array has an index. This is the position of the entry and, when used, its value is returned.

Screenshot 2018-09-17 12.08.20

In most programming languages, arrays also start with 0. To get the first (0) value in the array, it can be used with the reference using brackets. For example, using “[0]” would return the first value. Using “[3]” would return the forth entry.

Codepen Example:

See the Pen Learning JavaScript: Part 2: Data Types and Arrays by Dan Cox (@videlais) on CodePen.

Repl.it Example:

Test on Repl.it!

Mozilla Thimble:

Remix with Mozilla Thimble!