JSFiddle - React, Tailwind, and code Playground
by rexonms
JavaScript
const addTwoNumbers = (x) => (y) => x + y;
const addThree = addTwoNumbers(3);
const addFive = addTwoNumbers(5);
console.log('addThree 5', addThree(5));
console.log('addFive 5', addFive(5));
var counter = (() => {
var privateCounter = 0;
function changeBy(val) {
privateCounter += val;
}
return {
increment: function() {
changeBy(1);
},
decrement: function() {
changeBy(-1);
},
value: function() {
return privateCounter;
}
};
})();
console.log(counter.value()); // logs 0
counter.increment();
counter.increment();
// counter.changeBy(20);
console.log(counter.value()); // logs 2
counter.decrement();
console.log(counter.value()); // logs 1