FreeCodeCampChina / FreeCodeCampChina/freecodecamp.cn

全局变量如何声明

Open
#604 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
CSS
Stars
37.8k
Forks
1.4k
PR merge metrics
No merged PRs in 30d

Description

Challenge [Local Scope and Functions](https://freecodecamp.cn/challenges/local-scope-and-functions#?solution=%0Afunction%20myFunction()%20%7B%0Avar%20myVar%3D%22use%20strict%22%3B%0A%0A%20%20console.log(myVar)%3B%0A%7D%0AmyFunction()%3B%0A%0A%2F%2F%20%E8%AF%B7%E5%85%88%E8%BF%90%E8%A1%8C%E8%BF%99%E6%AE%B5%E4%BB%A3%E7%A0%81%EF%BC%8C%E5%B9%B6%E5%9C%A8%E5%B7%A6%E8%BE%B9%E7%9A%84%E8%BE%93%E5%87%BA%E5%8C%BA%E5%9F%9F%E6%88%96%E6%B5%8F%E8%A7%88%E5%99%A8%E7%9A%84%E6%8E%A7%E5%88%B6%E5%8F%B0%E4%B8%AD%E6%9F%A5%E7%9C%8B%E8%BE%93%E5%87%BA%0A%2F%2F%20%E7%94%B1%E4%BA%8E%20myVar%20%E5%9C%A8%20myFunction%20%E5%86%85%E5%A4%96%E5%9D%87%E6%B2%A1%E6%9C%89%E5%AE%9A%E4%B9%89%EF%BC%8C%E5%9B%A0%E6%AD%A4%E6%89%8D%E4%BC%9A%E6%9C%89%E6%8A%A5%E9%94%99%0A%0A%2F%2F%20%E7%8E%B0%E5%9C%A8%EF%BC%8C%E5%9C%A8%20myFunction%20%E4%B8%AD%E5%AE%9A%E4%B9%89%20myVar%EF%BC%8C%E5%B9%B6%E5%88%A0%E6%8E%89%20myFunction%20%E5%A4%96%E9%9D%A2%E7%9A%84%20console.log%20%E9%82%A3%E4%B8%80%E8%A1%8C%0A%0A) has an issue.
User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 SE 2.X MetaSr 1.0.
Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:
```javascript

function myFunction() {
var myVar="use strict";

console.log(myVar);
}
myFunction();

// 请先运行这段代码,并在左边的输出区域或浏览器的控制台中查看输出
// 由于 myVar 在 myFunction 内外均没有定义,因此才会有报错

// 现在,在 myFunction 中定义 myVar,并删掉 myFunction 外面的 console.log 那一行

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.