JavaScript function to calculate formula expressions.