// get type of variable
var number = 1
var string = 'hello world'
var dict = {a: 1, b: 2, c: 3}
console.log(typeof number) // number
console.log(typeof string) // string
console.log(typeof dict) // object
typeof variable;
// You can use the built-in method 'typeof' in order to check the variable datatype
//examples:
typeof "hello" // "string"
//or
var a = 1;
typeof(a);
//the output will be > 'number'
let store = [1,2,3]; console.log(typeof store);
> typeof "foo"
"string"
> typeof true
"boolean"
> typeof 42
"number"
typeof operando
> typeof "foo"
"string"
> typeof true
"boolean"
> typeof 42
"number"
function gettype(data) {
let itemType = Object.prototype.toString.call(data)
let type = ''
switch (itemType) {
case "[object Null]":
type = 'Null';
break;
case "[object Object]":
type = 'Object';
break;
case "[object Array]":
type = 'Array';
break;
case "[object String]":
type = 'String';
break;
case "[object Boolean]":
type = 'Boolean';
break;
case "[object Number]":
type = 'Number';
break;
}
return type
}
if(typeof variable == 'object'){
//
}
Object.prototype.toString.call(data)