Skip to content

Instantly share code, notes, and snippets.

@piknikki
Last active October 21, 2020 14:50
Show Gist options
  • Save piknikki/814b986780668596bd1d00b6cb638a38 to your computer and use it in GitHub Desktop.
Save piknikki/814b986780668596bd1d00b6cb638a38 to your computer and use it in GitHub Desktop.
Beginners Guide to data types

Data Types

This document is intended to be an introduction to the data types that are utilized in JavaScript.

  1. Numbers
  • Integers are whole numbers, without decimals or fractional parts of numbers. (ex. 42, 78)
  • Floats have a decimal and fractional parts. (ex. 1.23, 42.42)
  1. Strings Strings must be inside quotes. Whether you use single or double quotes is up to you (and your team). Even numbers are strings, if they're inside quotes. (ex. "hello world")
  2. Boolean A boolean is a variable that must resolve to true or false. (ex. var isToggled = true)
  3. Arrays A list. Arrays must be inside square brackets. The items inside an array can be any data type (string, number, more arrays, objects). (ex. [2, "hello", 4, "world", true])
  4. Objects A list of key/value pairs that are related (the relationship is important here, because the key refers to the value). An object is more dimensional than a plain old array, as it has pairs that are explicitly described. The key can be a number or a string, and the value can be any of the previously mentioned data types, and they are separated by a colon. (ex. var myObj = {myKey: 'myValue'})

Example using all of the above data types

var myNumber = 42;
var myString = "You're an angry little elf!!";
var myBoolean = true;
var myArray = ['candy', 'candy canes', 'candy corn', 'syrup'];
var myObject = {name: 'Buddy', species: 'Elf'}

Lastly, some kittens, to brighten your day. (I mean, surely kittens should be their own data type??)

Fluffy Kitten

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment