How can synchronous functions be smoothly switched to asynchronous functions in javascript projects?

  node.js, question

The title does seem a bit difficult to understand.
Because I am not very familiar with JS programming, I often encounter this problem when doing projects, and it has troubled me for a long time.
On this issue, let me give an example.
The project often uses the same code in many places. For convenience, I like to draw it out and write it into a function, such as this funA (). This function has a very simple function, which is to take some dom values, add, subtract, and then return the result.

function funA(){
 var i = document.getElementById(...).value;
 var j = document.getElementById(...).value;
 Return i plus j;

With funA (), the amount of code has decreased a lot. Until one day, the boss said that this function should be changed, instead of reading dom values, it should be pulled from the server.
It sounds very simple, but I was confused when I actually developed it.
This is because:

  1. FunA () is synchronized and returns the corresponding value whenever it is called. But the new funA () is asynchronous, after calling it, who knows when to return the data to me.

  2. Countless codes have called my funA () function. All codes calling funA () think that this function can return the desired number. I don’t want to change countless places because funA () reads the server.

  3. There are more funA () like functions that face this change. That is, functions that were originally synchronous must be changed to asynchronous one day.

Ask JS great god, how do you solve my problem?

Either write your pile of code that calls funA into the method that calls funA.
Either the funA call is changed to synchronous, or the asynchronous attribute in jQuery’s $ajax is changed to false.

A function cannot control the execution of your subsequent code.