feat: Add JavaScript core exercises and solutions
- Implemented exercises for array high-order methods, memory and execution, switch statements, and final review. - Added starter and answer files for each exercise to facilitate learning. - Created a runner HTML file to execute JavaScript code and display console outputs. - Updated README files to include exercise objectives, tasks, and usage instructions.
This commit is contained in:
16
03-javascript-core/09-scope-and-closure/answer.js
Normal file
16
03-javascript-core/09-scope-and-closure/answer.js
Normal file
@@ -0,0 +1,16 @@
|
||||
function createCounter() {
|
||||
let count = 0;
|
||||
|
||||
return function () {
|
||||
count += 1;
|
||||
return count;
|
||||
};
|
||||
}
|
||||
|
||||
const counterA = createCounter();
|
||||
const counterB = createCounter();
|
||||
|
||||
console.log("counterA 第一次:", counterA());
|
||||
console.log("counterA 第二次:", counterA());
|
||||
console.log("counterB 第一次:", counterB());
|
||||
console.log("每次调用 createCounter 都会创建一个新的闭包环境。");
|
||||
Reference in New Issue
Block a user