Javascript String Compare via localeCompare()

Description

Javascript String Compare via localeCompare()


// Checking string equivalence using localeCompare()
let aa = "AA";
let bb = "BB";

if (aa.localeCompare(bb) < 0) {
  console.log(aa + " is less than " + bb);
} else if (aa.localeCompare(bb) == 0) {
  console.log(aa + " is equal to " + bb);
} else if (aa.localeCompare(bb) > 0) {
  console.log(aa + " is greater than " + bb);
}



PreviousNext

Related