1// get type of variable
2
3var number = 1
4var string = 'hello world'
5var dict = {a: 1, b: 2, c: 3}
6
7console.log(typeof number) // number
8console.log(typeof string) // string
9console.log(typeof dict) // object
1> typeof "foo"
2"string"
3> typeof true
4"boolean"
5> typeof 42
6"number"
7
8if(typeof bar === 'number') {
9 //whatever
10}
1console.log(typeof 93);
2// Output = "number"
3
4console.log(typeof 'Maximum');
5// Output = 'string'
6
7console.log(typeof false);
8// Output = "boolean"
9
10console.log(typeof anUndeclaredVariable);
11// Output = "undefined"
1var x = 12345;
2console.log(typeof x) // number
3x = 'string';
4console.log(typeof x) // string
5x = { key: 'value' };
6console.log(typeof x) // object