freeCodeCamp/curriculum/challenges/chinese/02-javascript-algorithms-an.../basic-javascript/initializing-variables-with...

49 lines
868 B
Markdown
Raw Normal View History

---
id: 56533eb9ac21ba0edf2244a9
title: 使用赋值运算符初始化变量
challengeType: 1
videoUrl: 'https://scrimba.com/c/cWJ4Bfb'
forumTopicId: 301171
dashedName: initializing-variables-with-the-assignment-operator
---
# --description--
通常在声明变量的时候会给变量<dfn>初始化</dfn>一个初始值。
`var myVar = 0;`
创建一个名为 `myVar` 的变量,并指定其初始值 `0`
# --instructions--
通过关键字 `var` 定义一个变量 `a`,并给它一个初始值 `9`
# --hints--
你需要初始化 `a` 的值为 `9`
```js
assert(/var\s+a\s*=\s*9(\s*;?\s*)$/.test(code));
```
# --seed--
## --after-user-code--
```js
if(typeof a !== 'undefined') {(function(a){return "a = " + a;})(a);} else { (function() {return 'a is undefined';})(); }
```
## --seed-contents--
```js
```
# --solutions--
```js
var a = 9;
```