Skip to content

Instantly share code, notes, and snippets.

@jerlyrosa
Created October 1, 2021 01:29
Show Gist options
  • Save jerlyrosa/29538a5cf2c2a00ff63b7114806ab17b to your computer and use it in GitHub Desktop.
Save jerlyrosa/29538a5cf2c2a00ff63b7114806ab17b to your computer and use it in GitHub Desktop.
Ejemplos de closures
// CLOSURE
const anotherFunction = () =>{
var count = 0;
const countFuction =(value)=>{
return count += value;
}
return countFuction;
}
let test = anotherFunction();
test(1);
test(1);
test(1);
let zz = 1
//Recoradando el habito lexico.
const buildCount= (value) =>{
var count = value;
const countFuction =(value)=>{;
return console.log(count++)
}
return countFuction;
}
let test2 = buildCount(1);
test2();
test2();
let test3 = buildCount(5);
test3();
test3();
const fruits = () => {
console.log(fruit2)
if (true) {
var fruit1 = 'apple';
const fruit2 = 'banana';
let fruit3 = 'kiwi';
}
}
console.log(3**2)
fruits()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment