How to find type of variable in JavaScript?
In this tutorial, let’s learn how to identify the type of a variable in JavaScript.
In short, the answer in typeof. In JavaScript, the typeof operator returns the data type of its operand in the form of a string. The operand can be any object, function, or variable.
console.log(typeof "foo"); //string console.log(typeof true); //boolean console.log(typeof 17); //number console.log(typeof undefined); //undefined console.log(typeof justAnUndeclaredVariable); //undefined console.log(typeof {name: "Anand"}); //object console.log(typeof function() {} ); //function