1function doSomething(x) {
2 if(typeof(x) === 'string') {
3 alert('x is a string')
4 } else if(typeof(x) === 'number') {
5 alert('x is a number')
6 }
7}
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
1var x = 12345;
2console.log(typeof x) // number
3x = 'string';
4console.log(typeof x) // string
5x = { key: 'value' };
6console.log(typeof x) // object