# Checking Types
# JS type
# typeof operator
| x | typeof x |
|---|---|
| undefined | 'undefined' |
| null | 'object' |
| Boolean | 'boolean' |
| Number | 'number' |
| String | 'string' |
| Symbol | 'symbol' |
| Function | 'function' |
| All other objects | 'object |
# instanceof operator
This operator answers the question: has a value x been created by a class C?
x instanceof C
But primitive values are not instance of anything:
123 instanceof Number;
// false
"" instanceof String;
// false
"" instanceof Object;
// false
1
2
3
4
5
6
2
3
4
5
6
# Object.prototype.toString.call()
| Object.prototype.toString.call('An') | "[object String]" |
|---|---|
| Object.prototype.toString.call(1) | "[object Number]" |
| Object.prototype.toString.call(Symbol(1)) | "[object Symbol]" |
| Object.prototype.toString.call(null) | "[object Null]" |
| Object.prototype.toString.call(undefined) | "[object Undefined]" |
| Object.prototype.toString.call(function(){}) | "[object Function]" |
| Object.prototype.toString.call({name: 'An'}) | "[object Object]" |