1function isString(value) {
2 return typeof value === 'string' || value instanceof String;
3}
4
5isString(''); // true
6isString(1); // false
7isString({}); // false
8isString([]); // false
9isString(new String('teste')) // true
10
1if (typeof myVar === 'integer'){
2 //I am indeed an integer
3}
4
5if (typeof myVar === 'boolean'){
6 //I am indeed a boolean
7}
1console.log(typeof 93);
2// Output = "number"
3
4console.log(typeof 'Maximum');
5// Output = 'string'
6
7console.log(typeof false);
8// Output = "boolean"
9
10console.log(typeof anUndeclaredVariable);
11// Output = "undefined"
1var booleanValue = true;
2var numericalValue = 354;
3var stringValue = "This is a String";
4var stringObject = new String( "This is a String Object" );
5alert(typeof booleanValue) // displays "boolean"
6alert(typeof numericalValue) // displays "number"
7alert(typeof stringValue) // displays "string"
8alert(typeof stringObject) // displays "object"
9
1let eventValue = event.target.value;
2
3 if (/^\d+$/.test(eventValue)) {
4 eventValue = parseInt(eventValue, 10);
5 }
6
7//If value is a string, it converts to integer.
8
9//Otherwise it remains integer.