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 === 'string' || myVar instanceof String)
2// it's a string
3else
4// it's something else
5
1console.log(typeof "how are you?")
2"string"
3console.log(typeof false) / console.log(typeof true)
4"boolean"
5console.log(typeof 100)
6"number"
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.