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

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

I’ve tried this and it doesn’t work…

var a_string = "Hello, I'm a string.";

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

7 Answers
7

Leave a Comment