Files

51 lines
879 B
Markdown
Raw Permalink 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>一個初始值。
```js
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;
```