JavaScript jest zmiennym ciągiem
if (typeof myVar === 'string'){
//I am indeed a string
}
Grepper
if (typeof myVar === 'string'){
//I am indeed a string
}
// 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
if (typeof a_string === 'string') {
// this is a string
}
var value = "test string"
console.log(typeof value === "string")
if (typeof myVar === 'integer'){
//I am indeed an integer
}
if (typeof myVar === 'boolean'){
//I am indeed a boolean
}
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.