Answers for "javascript checking type of variable"

14

javascript how to know type of variable

var foo = "Hello";
console.log(typeof foo); // string
Posted by: Guest on February-20-2020
5

check data type in js

typeof("iAmAString");//This should return 'string'
//NO camelCase, as it is a JS Keyword
Posted by: Guest on March-21-2020
0

if typeof variable javascript

// check if a variable is of a certain type
var myVar = "This is a string";

if (typeof myVar === "string") {
	console.log("It's a string!");
} else if (typeof myVar === "number") {
	console.log("It's a number!");
};
// would return "It's a string!" in this case
Posted by: Guest on October-19-2021
1

check data type in js

var x = "Hello World";
typeof x; // "string"
Posted by: Guest on May-23-2020

Code answers related to "javascript checking type of variable"

Code answers related to "Javascript"

Browse Popular Code Answers by Language