Skip to content

Instantly share code, notes, and snippets.

@suhailgupta03
Created January 31, 2024 16:43
Show Gist options
  • Save suhailgupta03/86b19e367027491a706623bd5cba285d to your computer and use it in GitHub Desktop.
Save suhailgupta03/86b19e367027491a706623bd5cba285d to your computer and use it in GitHub Desktop.
function calculator(x, y) {
function add() {
return x + y;
}
function subtract() {
return x - y;
}
function multiply() {
return x * y;
}
return {
add: add,
subtract: subtract,
multiply: multiply
}
}
const calc = calculator(10, 5);
console.log(calc.add()); // 15
console.log(calc.subtract()); // 5
console.log(calc.multiply()); // 50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment