get type of variable code example
Example 1: find type of variable c#
string StringType
Type TheType = StringType.GetType();
Console.WriteLine(TheType.Name)
if(YourVar is YourType)
Console.WriteLine("Is your type you are testing for")
Example 2: get type of variable c#
string a = "This is a string";
Console.WriteLine(a.GetType())
Example 3: get type of var js
function doSomething(x) {
if(typeof(x) === 'string') {
alert('x is a string')
} else if(typeof(x) === 'number') {
alert('x is a number')
}
}
Example 4: javascript find type of variable
> typeof "foo"
"string"
> typeof true
"boolean"
> typeof 42
"number"
if(typeof bar === 'number') {
}
Example 5: type of javascript
if (typeof(value) !== "undefined") {
}
Example 6: check data type in javascript
typeof("string");
typeof(123);