Data Types

There are several types of data you may encounter in JavaScript.

Primitives

  • Boolean: Can only have a value of true or false. You may sometimes use a boolean as a "flag" for turning functionality on or off.
  • String: Used to store text information, this is a set of characters.
  • Number: Numerical information. Technically there are limits to how large or small of a number can safely be stored in a Number value, but it is unlikely you will encounter those limits during bootcamp.
  • BigInt: Used for numbers beyond the safe size limits of a Number. You will not need this during bootcamp (or maybe ever).
  • Undefined: This value has not been set. No information is available.
  • Null: An explicit way to signify that a value is empty.
  • Symbol: A special built-in object that is guaranteed to be unique. You will not need these for bootcamp (or maybe ever).

Four labeled images. 1. "Non-zero value" label above an image of a roll of toilet paper on a wall-mounted holder. 2. "0" label above an image of the same wall-mounted paper holder with an empty cardboard tube. 3. "null" label above an image of the same wall-mounted paper holder but no roll of any kind on it. 4. "undefined" label above an image of the blank wall only. No paper and no holder.

Objects

  • There are many types of data in JavaScript which are Objects, including Dates, Sets, WeakMaps and more. However, the main types that you'll use in bootcamp include:
    • "Normal" objects: Constructed of "key-value pairs" describing the properties of an object. An object begins and ends with curly braces, and key-value pairs are separated by commas. Values can be of any type. For example, an object representing a person might look like
    {
    name: 'Hercules',
    age: 18,
    todo: ['muck stables', 'slay hydra', 'get girdle']
    }
    • Array: A set of elements separated by commas. Elements of an array are often of a similar type and structure to each other. Begins and ends with square brackets. For example
    [1, 3, 5, 7]
    ['do', 're', 'mi', 'fa', 'sol', 'la', 'ti', 'do']

Resources

The Mozilla Developer Network has a really good explanation of JavaScript data types.