You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: update broken links and improve technical accuracy in IIFE/modules page
- Replace 3 broken article links (Google Developers, SitePoint) with working alternatives
- Replace unavailable YouTube video with Programming with Mosh tutorial
- Clarify var global scope claim applies to script mode, not modules
- Soften default exports best practice to 'common convention'
- Add note that error messages vary by browser
Copy file name to clipboardExpand all lines: docs/concepts/iife-modules.mdx
+13-10Lines changed: 13 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -181,6 +181,7 @@ const greet = () => "Hello!";
181
181
function() {
182
182
console.log("This causes a syntax error!");
183
183
}(); // SyntaxError: Function statements require a function name
184
+
// (exact error message varies by browser)
184
185
185
186
// ✓ This WORKS — Parentheses make it an expression
186
187
(function() {
@@ -258,7 +259,7 @@ There are several ways to write an IIFE. They all do the same thing:
258
259
259
260
### Why Were IIFEs Invented?
260
261
261
-
Before ES6 modules, JavaScript had a big problem: **everything was global**. Variables declared with [`var`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var) outside of functions became global, leading to conflicts:
262
+
Before ES6 modules, JavaScript had a big problem: **everything was global**. When scripts were loaded with regular `<script>` tags, variables declared with [`var`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var) outside of functions became global and were shared across all scripts on the page, leading to conflicts:
262
263
263
264
```javascript
264
265
// file1.js
@@ -1097,7 +1098,9 @@ import { sharedThing } from './shared.js';
1097
1098
import { sharedThing } from'./shared.js';
1098
1099
```
1099
1100
1100
-
### 4. Use Default Exports for Components/Classes
1101
+
### 4. Consider Default Exports for Components/Classes
1102
+
1103
+
A common convention is to use default exports when a module has one main purpose:
1101
1104
1102
1105
```javascript
1103
1106
// Components are usually one-per-file
@@ -1458,17 +1461,17 @@ Try to answer each question before revealing the solution:
1458
1461
<Cardtitle="ES6 Modules in Depth"icon="newspaper"href="https://ponyfoo.com/articles/es6-modules-in-depth">
1459
1462
Nicolás Bevacqua's thorough exploration of edge cases like circular dependencies and live bindings. Read this after you understand the basics.
1460
1463
</Card>
1461
-
<Cardtitle="Using JavaScript modules on the web"icon="newspaper"href="https://developers.google.com/web/fundamentals/primers/modules">
1462
-
Google's guide to using modules in browsers, including performance tips.
The V8 team's comprehensive guide covering native module loading, performance recommendations, and future developments. Includes practical tips on bundling vs unbundled deployment.
Interactive tutorial walking through module basics with live code examples. Covers both browser and Node.js usage patterns with clear, beginner-friendly explanations.
1466
1469
</Card>
1467
1470
<Cardtitle="All you need to know about Expressions, Statements and Expression Statements"icon="newspaper"href="https://dev.to/promhize/javascript-in-depth-all-you-need-to-know-about-expressions-statements-and-expression-statements-5k2">
1468
1471
Explains why `function(){}()` fails but `(function(){})()` works. The expression vs statement distinction finally makes sense after reading this.
1469
1472
</Card>
1470
-
<Cardtitle="Function Expressions vs Function Declarations"icon="newspaper"href="https://www.sitepoint.com/function-expressions-vs-declarations/">
1471
-
Covers hoisting behavior, named vs anonymous expressions, and arrow functions. Helps you choose the right syntax for each situation.
MDN's official reference on function expressions, covering syntax, hoisting behavior differences from declarations, and named function expressions. Includes interactive examples.
1472
1475
</Card>
1473
1476
</CardGroup>
1474
1477
@@ -1490,7 +1493,7 @@ Try to answer each question before revealing the solution:
1490
1493
<Cardtitle="Expressions vs. Statements in JavaScript"icon="video"href="https://www.youtube.com/watch?v=WVyCrI1cHi8">
1491
1494
Uses simple examples to show why expressions produce values and statements perform actions. Essential for understanding IIFE syntax.
1492
1495
</Card>
1493
-
<Cardtitle="JavaScript - Expression vs. Statement"icon="video"href="https://www.youtube.com/watch?v=3jDpNGJkupA">
1494
-
Answers "can I use this in an if condition?" and similar practical questions. Helps you recognize expressions vs statements in real code.
1496
+
<Cardtitle="JavaScript Functions — Programming with Mosh"icon="video"href="https://www.youtube.com/watch?v=N8ap4k_1QEQ">
1497
+
Comprehensive overview of JavaScript functions covering declarations, expressions, hoisting, and scope. Clear explanations with practical examples.
0 commit comments