IIFE in JavaScript

(function () {
console.log('IIFE')
})()
(() => {
console.log('IIFE')
})()
function func(){
console.log('IIFE')
}

func()
var b = 10

function print(){
b = 8
console.log(b) // output: 8
}

print()

console.log(b) // output: 8
var b = 10

function print(){
let b = 8
console.log(b) // output: 8
}

print()

console.log(b) // output: 10
var a = 8;

((a) => {
a = 9; // modifying the copy of 'a'
console.log(a); // output: 9
})(a) // passing a copy of variable as an argument

console.log(a) // output: 8
(async () => {
const get = await fetch(url)
// do something
})()

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Murtuza

Murtuza

Full Stack Developer | Content Creator | Technical Writer