IIFE immediately invoked function expressions - Javascript Function

Javascript examples for Function:Immediately Invoked Function Expressions IIFE

Description

IIFE immediately invoked function expressions

Demo Code

// function game() {
//   var score = Math.random() * 10;
//   console.log(score >= 5);
// }/*  ww  w .  ja  v  a2s .co  m*/
// game();

(function() {
  var score = Math.random() * 10;
  console.log(score >= 5);
})();

//we can pass an argument 
(function(goodLuck) {
  var score = Math.random() * 10;
  console.log(score >= (5 - goodLuck));
})(5);

Related Tutorials