After creating a POST route, I encountered unexpected behavior in the code below. The message variable does not display the expected output.
app.post("/", function (req, res, error) {
var message = "";
tableSvc.createTable("tableName", function (error, result,response){
if (error)
message += "There was an error in creating this table";
else
message += "Table created succesfully";
});
console.log(message);
});
Instead of showing the appropriate messages, an empty string is printed out. Despite executing the callback function and logging it to the console from within that function, the desired strings are not displayed as expected.
This confusion points to my unfamiliarity with JavaScript and callbacks. What might be causing my code to behave unexpectedly?