Answers for "if typeof variable javascript"

14

javascript how to know type of variable

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

typeof in js

var someValue = 'this is string';
console.log(typeof(someValue)); // this will return string
Posted by: Guest on March-11-2021
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

Code answers related to "Javascript"

Browse Popular Code Answers by Language