String Comparison


#1

Is there a way to make a conditional that evaluate a string for being a string?

EX:

if (x === String)
{
console.log("those are strings");
}
else if (x != String)
{
console.log("those are not strings");
}

or in a more concise way:

"if this variable here IS a string(regardless of the value it has) do this"


#2

you can use the local compare method

string_a.localeCompare(string_b);

/* Expected Returns:

0: exact match

-1: string_a < string_b

1: string_a > string_b

*/


#3

Try using the typeof operator:

if (typeof x === 'string') {

#4

True. I'd forgotten about it. Thanks.