How can I check if a var is a string in JavaScript?

You were close:

if (typeof a_string === 'string') {
    // this is a string
}

On a related note: the above check won’t work if a string is created with new String('hello') as the type will be Object instead. There are complicated solutions to work around this, but it’s better to just avoid creating strings that way, ever.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)