3.0 KiB
3.0 KiB
title | localeTitle |
---|---|
Compare Scopes of the var and let Keywords | 比较var的范围并让关键字 |
如果卡住,请记得使用**Read-Search-Ask
** 。尝试配对程序并编写自己的代码
问题说明:
我们需要改变var
来let
我们的职能范围和添加let
我们的块范围。
提示:1
- 找到
var
并替换为let
。
现在尝试解决问题
- 将
let
添加到if语句中的变量i
。
现在尝试解决问题
扰流警报!
提前解决!
基本代码解决方案
function checkScope() {
"use strict";
let i = "function scope";
if (true) {
let i = "block scope";
console.log("Block scope i is: ", i);
}
console.log("Function scope i is: ", i);
return i;
}
代码说明:
通过使用let
您可以声明与其范围相关的变量。
相关链接
捐款说明:
- 请勿添加与任何现有解决方案类似的解决方案。如果您认为它**相似但更好** ,那么尝试合并(或替换)现有的类似解决方案。
- 添加解决方案的说明。
- 将解决方案分为以下类别之一 - 基本 , 中级和高级 。
- 如果您添加了任何**相关的主要内容,**请仅添加您的用户名。 ( 不要 删除任何现有的用户名 )