JSFiddle - React, Tailwind, and code Playground
JavaScript
// Your example
var tax = 10;
var totalPrice = function (quantity, price) {
return (price * quantity) * (tax + 1.0);
};
var price = totalPrice(1, 1);
console.log ("Price YE is : " + price);
// Example 1 return function
function generatePriceCalculator(tax) {
return function(quantity, price) {
return (price * quantity) * (tax + 1.0);
};
};
var priceCalculator = generatePriceCalculator(20);
var price1 = priceCalculator(1, 1);
console.log ("Price Example 1 is : " + price1);
// Example 2 function return tax
function getTax() {
return 30;
}
var totalPrice2 = function (quantity, price) {
var tax = getTax();
return (price * quantity) * (tax + 1.0);
};
var price2 = totalPrice2(1, 1);
console.log ("Price Example 2 is : " + price2);