if string javascript
snippet in javascript

if string javascript

user392

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

javascript is variable a string

user2237

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

check if value is a string javascript

user8341

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.