Your problem is you need to read up on asynchronous programming in JavaScript, such as
https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Introducing
The grpc_web call is setting up a callback, and the reason the code jumps around is that the code isn't being run yet. It will be executed at a later time when the RPC finishes.
You can reproduce the same issue without grpc using the following code:
```javascript
function getBook() {
var bookTitle;
setTimeout(0, () => {
bookTitle = "Hello World";
console.log(bookTitle);
});
console.log(bookTitle);
return bookTitle;
}
```
Here, the callback set in the timeout function will be called after getBook returns.
You need to modify your code to make it asynchronous. The same problem would arise with any other asynchronous javascript library.