Skip to content

Instantly share code, notes, and snippets.

@robwilson1
Last active August 21, 2018 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robwilson1/06ce0233ce925ef9b23b99f717cc70ef to your computer and use it in GitHub Desktop.
Save robwilson1/06ce0233ce925ef9b23b99f717cc70ef to your computer and use it in GitHub Desktop.
Types

Types

Numbers

Numbers in JavaScript can be both positive, negative, whole numbers or floats.

Examples of a number:

  • 123
  • -47
  • 0
  • 1.45
  • -5.33

Boolean

A Boolean is true or false.

String

A String is one of more characters wrapped in single or double speechquotes.

Examples of a string:

  • 'hello'
  • "Goodbye"
  • 'a'
  • "1"

Array

An Array is a collection of 0 or more elements wrapped in square brackets. In an array you only declare the values

Examples of an array:

  • [1, 2, 3]
  • ['a', 'b', 'c']
  • [1, 2, 'a', 'b']
  • []

Object

An Object is also a collection of 0 or more elements wrapped in curly braces. With an Object however, you can name the key as well as the value.

Example of an Object:

	{
		name: 'Bobbie Dazzler',
		age: 20,
		male: true,
		friends: [ 'Joe', 'Lucy' ]
	}

Undefined

This is a special type for when something has been declared, but no value has been set. It is also used when you try to use something that does not exist.

In terms of undefined vs null, undefined it is what JavaScript itself will set.

Null

In terms of undefined vs null, null it is what YOU will set. JavaScript will never set something to null on its own.

Avoid using it.

NaN

Means Not a Number. It is a special type you will not need to use.

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