javascript

The Types of Data

There are four main types of data in Javascript:

  1. numbers e.g. 1, 2, 42, 3.14, etc
  2. strings e.g. "something like this, a long or short string of text"
  3. arrays e.g. ["a group of data", "usually a group of related data", "such as usernames, form values, etc."]
  4. objects e.g. { name: "Steve", hobby: "Gardening", age: 42, children: ["Bobby", "Dave"] }


Notice how the object example in #4 contains an array. Objects and arrays can contain other objects and arrays.


Here are some examples of creating variables to store these types of data:


// Creating a number:
let people = 3;

// Creating an array:
let peopleList = ["Steve", "Bobby", "Dave"];

// Creating a string:
let parentName = "Steve";

// Creating an object with properties inside it which are other types,
// name is a string, hobby is a string, age is a number, and children is an array containing two strings:
let steve = { name: "Steve", hobby: "Gardening", age: 42, children: ["Bobby", "Dave"] }