1> typeof "foo"
2"string"
3> typeof true
4"boolean"
5> typeof 42
6"number"
7
8if(typeof bar === 'number') {
9 //whatever
10}
1//typeof() will return the type of value in its parameters.
2//some examples of types: undefined, NaN, number, string, object, array
3
4//example of a practical usage
5if (typeof(value) !== "undefined") {//also, make sure that the type name is a string
6 //execute code
7}
1// You can use the built-in method 'typeof' in order to check the variable datatype
2
3//examples:
4
5typeof "hello" // "string"
6
7//or
8var a = 1;
9typeof(a);
10//the output will be > 'number'