3項演算子

const num = '1500';
const result =
  typeof num === "number" ? num.toLocaleString() : "数値を設定してください";
console.log(result);