2021-06-15 00:49:18 -07:00
|
|
|
---
|
|
|
|
id: 56533eb9ac21ba0edf2244a9
|
2021-07-21 20:53:20 +05:30
|
|
|
title: Inicializar variáveis com o operador de atribuição
|
2021-06-15 00:49:18 -07:00
|
|
|
challengeType: 1
|
|
|
|
videoUrl: 'https://scrimba.com/c/cWJ4Bfb'
|
|
|
|
forumTopicId: 301171
|
|
|
|
dashedName: initializing-variables-with-the-assignment-operator
|
|
|
|
---
|
|
|
|
|
|
|
|
# --description--
|
|
|
|
|
2021-07-26 23:39:21 +09:00
|
|
|
É comum <dfn>inicializar</dfn> a variável com um valor inicial na mesma linha em que é declarada.
|
2021-06-15 00:49:18 -07:00
|
|
|
|
|
|
|
```js
|
|
|
|
var myVar = 0;
|
|
|
|
```
|
|
|
|
|
2021-07-26 23:39:21 +09:00
|
|
|
Crie uma nova variável chamada `myVar` e atribua o seu valor inicial como `0`.
|
2021-06-15 00:49:18 -07:00
|
|
|
|
|
|
|
# --instructions--
|
|
|
|
|
2021-07-26 23:39:21 +09:00
|
|
|
Defina uma variável `a` com `var` e a inicialize com o valor de `9`.
|
2021-06-15 00:49:18 -07:00
|
|
|
|
|
|
|
# --hints--
|
|
|
|
|
2021-07-14 21:02:51 +05:30
|
|
|
Você deve inicializar `a` para o valor de `9`.
|
2021-06-15 00:49:18 -07:00
|
|
|
|
|
|
|
```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;
|
|
|
|
```
|