2018-10-10 18:03:03 -04:00
---
id: 56533eb9ac21ba0edf2244a8
2021-02-06 04:42:36 +00:00
title: Storing Values with the Assignment Operator
2018-10-10 18:03:03 -04:00
challengeType: 1
2020-04-29 18:29:13 +08:00
videoUrl: 'https://scrimba.com/c/cEanysE'
forumTopicId: 18310
2021-01-13 03:31:00 +01:00
dashedName: storing-values-with-the-assignment-operator
2018-10-10 18:03:03 -04:00
---
2020-12-16 00:37:30 -07:00
# --description--
2021-02-06 04:42:36 +00:00
In JavaScript, you can store a value in a variable with the < dfn > assignment</ dfn > operator (`=` ).
2020-12-16 00:37:30 -07:00
`myVariable = 5;`
2021-02-06 04:42:36 +00:00
This assigns the `Number` value `5` to `myVariable` .
2020-12-16 00:37:30 -07:00
2021-02-06 04:42:36 +00:00
If there are any calculations to the right of the `=` operator, those are performed before the value is assigned to the variable on the left of the operator.
2020-04-29 18:29:13 +08:00
```js
2021-02-06 04:42:36 +00:00
var myVar;
2020-04-29 18:29:13 +08:00
myVar = 5;
```
2021-02-06 04:42:36 +00:00
First, this code creates a variable named `myVar` . Then, the code assigns `5` to `myVar` . Now, if `myVar` appears again in the code, the program will treat it as if it is `5` .
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --instructions--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
Assign the value `7` to variable `a` .
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
# --hints--
2018-10-10 18:03:03 -04:00
2021-02-06 04:42:36 +00:00
You should not change code above the specified comment.
2018-10-10 18:03:03 -04:00
2020-12-16 00:37:30 -07:00
```js
2021-02-06 04:42:36 +00:00
assert(/var a;/.test(code));
2018-10-10 18:03:03 -04:00
```
2021-02-06 04:42:36 +00:00
`a` should have a value of 7.
2018-10-10 18:03:03 -04:00
```js
2020-12-16 00:37:30 -07:00
assert(typeof a === 'number' & & a === 7);
2018-10-10 18:03:03 -04:00
```
2021-01-13 03:31:00 +01:00
# --seed--
## --before-user-code--
```js
if (typeof a != 'undefined') {
a = undefined;
}
```
## --after-user-code--
```js
(function(a){return "a = " + a;})(a);
```
## --seed-contents--
```js
// Setup
var a;
// Only change code below this line
```
2020-12-16 00:37:30 -07:00
# --solutions--
2021-01-13 03:31:00 +01:00
```js
var a;
a = 7;
```