String Comparison


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


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”


you can use the local compare method


/* Expected Returns:

0: exact match

-1: string_a < string_b

1: string_a > string_b



Try using the typeof operator:

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


True. I’d forgotten about it. Thanks.