Learning JavaScript
- Part 1: Creating and Using Variables
- Part 2: Data Types and Arrays
- Part 3: Functions
- Part 4: Objects
- Part 5: Document Object Model
- Part 6: Conditional Statements
- Part 7: Loops
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.
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
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
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
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.
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.
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.
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.