Skip to content

Commit ff2f281

Browse files
Phillip MacEachronPhillip MacEachron
authored andcommitted
completed second stretch goal of experimenting with IIFEs
1 parent 01eb1a5 commit ff2f281

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

‎assignments/iife.js‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// file to play with IIFEs (Immediately Invoked Function Expressions)
2+
3+
console.log(' === IIFE stuff ===');
4+
5+
(function (){
6+
const daysInWeek = 7;
7+
const weeksInYear = 52;
8+
const daysInYear = daysInWeek * weeksInYear;
9+
10+
console.log(`There're about ${daysInYear} days in a year.`);
11+
})();
12+
// can reuse this variable name without issue since its in an IIFE previously
13+
const daysInYear = 365;
14+
15+
console.log(`There're actually ${daysInYear} days in a year.`);
16+
17+
18+
// trying it with arrow function
19+
(() => {
20+
let daysInMonth = 7 * 4;
21+
console.log(`There are about ${daysInMonth} days in a month.`);
22+
})();
23+
24+
let daysInMonth = 30;
25+
26+
console.log(`There are actually ${daysInMonth} days in most months.`);
27+
28+
29+
30+

‎assignments/index.html‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
<script src="array-methods.js"></script>
1111
<script src="callbacks.js"></script>
1212
<script src="closure.js"></script>
13+
<script src="iife.js"></script>
14+
1315
</head>
1416

1517
<body>

0 commit comments

Comments
 (0)