0

Why does an IIFE need a semicolon? Why doesn't it just read the newlines as linebreaks? The following code:

(function(){
  console.log(`Hello there`)
})()

(function(){
  console.log(`IIFE ran..`)
})()

returns:

temp.js:2 Hello there
temp.js:5 Uncaught TypeError: (intermediate value)(...) is not a function
    at temp.js:5

However, the following does work:

(function(){
  console.log(`Hello there`)
})();

(function(){
  console.log(`IIFE ran..`)
})()

Edit: Thanks for the comments. The help is greatly appreciated

0 Answers0