How to compare two strings in JavaScript?

To compare two strings in JavaScript, use the regular >, >=, <, <=, === operators.

Here's how you do it:

const allan = 'Allan';
const bob = 'Bob';
const carl = 'Carl';

// Two Bob's are same: true
console.log('Two Bobs are same:', bob === bob);

// Allan is before Bob: true
console.log('Allan is before Bob:', allan < bob);

// Bob is before Carl: true
console.log('Bob is before Carl:', bob < carl); 

// Allan is after Carl: false
console.log('Allan is after Carl:', allan > carl);