Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:
// 声明变量
let Name;
let Age;
// 赋值
Name = "小王";
Age = 18;
console.log(Name + "今年" + Age + "岁。");
// 声明函数
function go(add) {
return "我要去" + add;
}
console.log(go("北京"));
let Home;
Home = "广西南宁";
console.log(go(Home));
// 1. 块作用域
{
let Name = "小张";
console.log(Name); //结果正常
}
//console.log(Name); //这里会出错,块外部不能访问内部变量
// 2. 函数作用域
function sayHai(Name) {
let getName = Name;
console.log("你好" + getName); //结果正常;
}
sayHai("小王");
// console.log(getName); 这里会出错,函数外部不能访问内部变量
// 3. 全局作用域
let Name = "小雨"; //这是全局变量,任何地方都可访问
{
console.log("你好" + Name); //块内可用
}
{
{
{
console.log("你好" + Name + ",又见面了。"); //多层嵌套也可用
}
}
}
function say() {
console.log(Name + "你吃了吗?");
}
say();
function hai() {
return function () {
return function () {
return "再见了" + Name + ",我回家了。";
};
};
}
console.log(hai()()());
// 声明常量
const ADD = "北京";
console.log(ADD);