//typeof() will return the type of value in its parameters.
//some examples of types: undefined, NaN, number, string, object, array
//example of a practical usage
if (typeof(value) !== "undefined") {//also, make sure that the type name is a string
//execute code
}
console.log(typeof(variableName))
const name = 'ram';
typeof(name); // returns "string"
const number = 4;
typeof(number); //returns "number"
const valueChecked = true;
typeof(valueChecked); //returns "boolean"
const a = null;
typeof(a); // returns "object"
var miFuncion = new Function("5+2")
var forma = "redonda"
var tamano = 1
var hoy = new Date()
typeof miFuncion === 'function'
typeof forma === 'string'
typeof tamano === 'number'
typeof hoy === 'object'
typeof noExiste === 'undefined'
exports.is = (data) => {
const isArray = Array.isArray(data) && 'array'
const isObject = data == {} && 'object'
const isNull = data == null && 'null'
const isGrouping = isArray || isObject || isNull
const isCheck = !isGrouping ? typeof data : isGrouping
const isTypeData = ['number','string','array','symbol','object','undefined','null','function', 'boolean']
const isMatch = isTypeData.indexOf(isCheck)
const isResult = isTypeData[isMatch]
return isResult
}
typeof("iAmAString");//This should return 'string'
//NO camelCase, as it is a JS Keyword
typeof
typeof operand
// data is of undefined type
let data;
// data is of integer type
data = 5;
// data is of string type
data = "JavaScript Programming";