Skip to content

Instantly share code, notes, and snippets.

@haingdc
Created January 30, 2018 10:11
Show Gist options
  • Save haingdc/ec6ca7a1c0c4429e9dc759cbc2720d3f to your computer and use it in GitHub Desktop.
Save haingdc/ec6ca7a1c0c4429e9dc759cbc2720d3f to your computer and use it in GitHub Desktop.
iife presence
var person = "Alice";
var fruit = "apple";
var fruits = [
"banana",
"lemon",
"mango",
"peace"
];
for (var i = 0; i < fruits.length; i++) {
(function() {
var fruit = fruits[i];
console.log(person + " has a " + fruit);
})();
}
console.log(person + " has an " + fruit);
// Outputs:
// Alice has a banana
// Alice has a lemon
// Alice has a mango
// Alice has a peace
// Alice has an apple <- cái ta cần
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment