Advertisement
Guest User

jskod

a guest
Apr 28th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const heroes = []
  2. heroes[0] = "batman"
  3. heroes[1] = "spiderman";
  4.  
  5. //Function IIFE
  6. (function IIFE() {
  7.   console.log("Hello!")
  8. })()
  9.  
  10. //Const IIFE
  11. const IFEF = (() => {
  12.   console.log("Hello")
  13. })()
  14.  
  15. const foo = () => {
  16.   var a = 1
  17.   if (a >= 1) {
  18.     const b = 2;
  19.     console.log("yay")
  20.   }
  21. }
  22. foo()
  23.  
  24.  
  25. //Closure
  26.  
  27. const makeAdder = (x) => {
  28.   const add = (y) => {
  29.     return y + x
  30.   }
  31.   return add
  32. }
  33.  
  34. const plusOne = makeAdder(1)
  35. const plusTen = makeAdder(10)
  36.  
  37. console.log(plusOne(3))
  38. console.log(plusOne(41))
  39. console.log(plusTen(13))
  40.  
  41. //Modules
  42.  
  43. const User = () => {
  44.   let username, password
  45.  
  46.   const doLogin = (user, pw) => {
  47.     username = user
  48.     password = pw
  49.   }
  50.  
  51.   const publicAPI = {
  52.     login: doLogin
  53.   }
  54.   return publicAPI
  55. }
  56.  
  57. //Create a 'User' module instance
  58. const fred = User()
  59. fred.login("fred", "12Battery34!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement