Knowing your types is one of the most useful tools you have available to you as a programmer. In JavaScript, types can be super confusing. Here are some examples of each of the types.
Boolean
true
false
7 === 5
7 !== 5
Number
1
3
18
-17.6
12-7.2
String
'hello'
'hello'+'world'
'hello'+' '+'world'
Array
[1,2,3,4]
['one fish', 'two fish', 'red fish', 'blue fish']
[[1,2], [3,4], [5,6]]
'this is a test'.split(' ')
Object
Date
Dates are a type of Object
var now = new Date();
RegExp
Regular Expressions are a type of Object
var checkName = new RegExp('[a-zA-Z]+ [a-zA-Z]+');
var checkName = /[a-zA-Z]+ [a-zA-Z]+/;
Vanilla JavaScript Element
Vanilla JavaScript Elements are a type of Object
document.querySelector('#foo')
document.querySelector('main')
document.getElementById('foo')
e.target
jQuery Element
jQuery Elements are a type of Object
$('main')
$('#foo')
$('.bar')
$(e.target)
React Element
React Elements are a type of Object
<UniForm />
React.createElement(UniForm)
Backbone View
Backbone Views are a type of Object
var unicornDisplay = new UnicornView();
Backbone Model
Backbone Models are a type of Object
var unicorn = new UnicornModel();
Backbone Collection
Backbone Collections are a type of Object
var unicorns = new UnicornCollection();
Function
parseFloat(...)
isNaN(...)
Constructor
Constructors are a type of Function
Date
RegExp
var UnicornView = Backbone.View.extend({...})
var UnicornModel = Backbone.Model.extend({...})
var UnicornCollection = Backbone.Collection.extend({...})
var UniForm = React.createClass({...})
Method
Methods are a type of Function
console.log(...)
document.write(...)
Math.abs(...)
Math.ceil(...)
Math.floor(...)