JSFiddle - React, Tailwind, and code Playground

HTML

<button>Click to change to erase</button>

JavaScript

var erasing = false;
$("button").click(function () {
    erasing = !erasing;
      $(this).text(function (_, curText) {
          return curText == "Click to change to paint brush" ? "Click to change to eraser" :  "Click to change to paint brush" ;
      });
    console.log(erasing);
  });