JavaScript Datatypes in Javascript typeof

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

typeof is the 'official' function that one uses to get the type in javascript, however in certain cases it might yield some unexpected results ...

1. Strings

typeof "String" or
typeof Date(2011,01,01)

"string"

2. Numbers

typeof 42

"number"

3. Bool

typeof true (valid values true and false)

"boolean"

4. Object

typeof {} or
typeof [] or
typeof null or
typeof /aaa/ or
typeof Error()

"object"

5. Function

typeof function(){}

"function"

6. Undefined

var var1; typeof var1

"undefined"



Got any JavaScript Question?