Skip to content

Commit 2249c84

Browse files
committed
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
1 parent 1493bac commit 2249c84

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

docs/concepts/iife-modules.mdx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ const greet = () => "Hello!";
181181
function() {
182182
console.log("This causes a syntax error!");
183183
}(); // SyntaxError: Function statements require a function name
184+
// (exact error message varies by browser)
184185

185186
// ✓ This WORKS — Parentheses make it an expression
186187
(function() {
@@ -258,7 +259,7 @@ There are several ways to write an IIFE. They all do the same thing:
258259

259260
### Why Were IIFEs Invented?
260261

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:
262263

263264
```javascript
264265
// file1.js
@@ -1097,7 +1098,9 @@ import { sharedThing } from './shared.js';
10971098
import { sharedThing } from './shared.js';
10981099
```
10991100

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:
11011104

11021105
```javascript
11031106
// Components are usually one-per-file
@@ -1458,17 +1461,17 @@ Try to answer each question before revealing the solution:
14581461
<Card title="ES6 Modules in Depth" icon="newspaper" href="https://ponyfoo.com/articles/es6-modules-in-depth">
14591462
Nicolás Bevacqua's thorough exploration of edge cases like circular dependencies and live bindings. Read this after you understand the basics.
14601463
</Card>
1461-
<Card title="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.
1464+
<Card title="JavaScript modules — V8" icon="newspaper" href="https://v8.dev/features/modules">
1465+
The V8 team's comprehensive guide covering native module loading, performance recommendations, and future developments. Includes practical tips on bundling vs unbundled deployment.
14631466
</Card>
1464-
<Card title="Understanding ES6 Modules" icon="newspaper" href="https://www.sitepoint.com/understanding-es6-modules/">
1465-
Walks through setting up modules in both browser and Node.js environments. Includes a complete example project structure you can copy.
1467+
<Card title="Modules — javascript.info" icon="newspaper" href="https://javascript.info/modules-intro">
1468+
Interactive tutorial walking through module basics with live code examples. Covers both browser and Node.js usage patterns with clear, beginner-friendly explanations.
14661469
</Card>
14671470
<Card title="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">
14681471
Explains why `function(){}()` fails but `(function(){})()` works. The expression vs statement distinction finally makes sense after reading this.
14691472
</Card>
1470-
<Card title="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.
1473+
<Card title="Function Expressions — MDN" icon="newspaper" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/function">
1474+
MDN's official reference on function expressions, covering syntax, hoisting behavior differences from declarations, and named function expressions. Includes interactive examples.
14721475
</Card>
14731476
</CardGroup>
14741477

@@ -1490,7 +1493,7 @@ Try to answer each question before revealing the solution:
14901493
<Card title="Expressions vs. Statements in JavaScript" icon="video" href="https://www.youtube.com/watch?v=WVyCrI1cHi8">
14911494
Uses simple examples to show why expressions produce values and statements perform actions. Essential for understanding IIFE syntax.
14921495
</Card>
1493-
<Card title="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+
<Card title="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.
14951498
</Card>
14961499
</CardGroup>

0 commit comments

Comments
 (0)