JavaScript Semicolon Gotcha: Understanding ASI

If you think semicolons don’t matter in JavaScript…? Click “more” before you scroll ... Skipping semicolons feels harmless… 👀 Until this happens 👇 const arr = [1, 2, 3] (function () { console.log("Hello 👋") })() 👉 Error: arr is not a function 😳 👉 Why? JavaScript thinks you're calling the array as a function Because there’s no semicolon before the IIFE 👉 Fix: const arr = [1, 2, 3]; 👉 Small symbol… big problem 😬 This is due to Automatic Semicolon Insertion (ASI) ⚡ Follow for more simple dev concepts 🚀 #JavaScript #Developers #WebDevelopment #Coding #Debugging #Relatable

  • text

To view or add a comment, sign in

Explore content categories