How to stop CKEditor from adding unwanted characters with JavaScript?

To stop CKEditor from adding unwanted characters with JavaScript, w ecan set a few settings.

For instance, we write

CKEDITOR.editorConfig = (config) => {
  config.enterMode = CKEDITOR.ENTER_BR;
  config.entities = false;
  config.basicEntities = false;
};

to set the editorConfig to a function that sets the editor config.

We set enterMode to CKEDITOR.ENTER_BR to convert empty p elements to br elements.

And we set entities and basicEntities to stop characters from being escaped.