Numbers in JavaScript can be both positive, negative, whole numbers or floats.
Examples of a number:
- 123
- -47
- 0
- 1.45
- -5.33
A Boolean is true
or false
.
A String is one of more characters wrapped in single or double speechquotes.
Examples of a string:
- 'hello'
- "Goodbye"
- 'a'
- "1"
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']
- []
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' ]
}
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.
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.
Means Not a Number. It is a special type you will not need to use.