Files
charlie 877acb5a8f 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.
2026-03-13 11:09:19 +08:00

29 lines
800 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

console.log("var 声明前:", lessonType);
var lessonType = "JavaScript";
console.log("var 声明后:", lessonType);
// console.log("let 声明前:", chapterType);
// let 在声明前处于暂时性死区,直接访问会报错。
function compareScope() {
if (true) {
var lessonName = "变量";
let chapterName = "作用域";
const stage = "进阶";
console.log("块内:", lessonName, chapterName, stage);
}
console.log("块外仍能访问 var", lessonName);
// console.log(chapterName);
// chapterName 是 let 声明的块级作用域变量,离开 if 代码块后就不能访问。
}
compareScope();
const level = "核心阶段";
console.log("const 初始值:", level);
// level = "下一阶段";
// const 不能被重新赋值,否则会报错。