xxxxxxxxxx
let eventValue = event.target.value;
if (/^\d+$/.test(eventValue)) {
eventValue = parseInt(eventValue, 10);
}
//If value is a string, it converts to integer.
//Otherwise it remains integer.
xxxxxxxxxx
// Example 1:
const string = "Hello world!";
n = string.includes("world");
// n is equal to true in Example 1
// Example 2:
const string = "Hello world!, I am Kavyansh";
n = string.includes("I am Aman");
// n is equal to false in Example 2
// Note: the .includes method is case sensitive
xxxxxxxxxx
function isString(value) {
if (typeof value === "string") {
return true;
}
return false;
}
xxxxxxxxxx
if (typeof myVar === 'integer'){
//I am indeed an integer
}
if (typeof myVar === 'boolean'){
//I am indeed a boolean
}
xxxxxxxxxx
function isString(variable) {
return typeof variable === 'string';
}
// Example usage:
console.log(isString('Hello')); // true
console.log(isString(123)); // false
xxxxxxxxxx
const str = 'This is my example string!';
const substr = 'my';
console.log(str.includes(substr));
xxxxxxxxxx
var booleanValue = true;
var numericalValue = 354;
var stringValue = "This is a String";
var stringObject = new String( "This is a String Object" );
alert(typeof booleanValue) // displays "boolean"
alert(typeof numericalValue) // displays "number"
alert(typeof stringValue) // displays "string"
alert(typeof stringObject) // displays "object"
xxxxxxxxxx
function isString(x) {
return Object.prototype.toString.call(x) === "[object String]"
}