Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const heroes = []
- heroes[0] = "batman"
- heroes[1] = "spiderman";
- //Function IIFE
- (function IIFE() {
- console.log("Hello!")
- })()
- //Const IIFE
- const IFEF = (() => {
- console.log("Hello")
- })()
- const foo = () => {
- var a = 1
- if (a >= 1) {
- const b = 2;
- console.log("yay")
- }
- }
- foo()
- //Closure
- const makeAdder = (x) => {
- const add = (y) => {
- return y + x
- }
- return add
- }
- const plusOne = makeAdder(1)
- const plusTen = makeAdder(10)
- console.log(plusOne(3))
- console.log(plusOne(41))
- console.log(plusTen(13))
- //Modules
- const User = () => {
- let username, password
- const doLogin = (user, pw) => {
- username = user
- password = pw
- }
- const publicAPI = {
- login: doLogin
- }
- return publicAPI
- }
- //Create a 'User' module instance
- const fred = User()
- fred.login("fred", "12Battery34!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement