js check type string code example

Example 1: if string javascript

if (typeof myVar === 'string') { /* code */ };

Example 2: check type string javascript

if (typeof myVar === 'string' || myVar instanceof String)
// it's a string
else
// it's something else

Example 3: check type javascript

console.log(typeof "how are you?")
"string"
console.log(typeof false) / console.log(typeof true)
"boolean"
console.log(typeof 100)
"number"

Example 4: js check if variable is string

if (typeof myVar === 'integer'){
    //I am indeed an integer
}

if (typeof myVar === 'boolean'){
    //I am indeed a boolean
}