2018-09-30 23:01:58 +01:00
---
id: 56533eb9ac21ba0edf2244a8
title: Storing Values with the Assignment Operator
challengeType: 1
2019-02-14 12:24:02 -05:00
videoUrl: 'https://scrimba.com/c/cEanysE'
2019-07-31 11:32:23 -07:00
forumTopicId: 18310
2018-09-30 23:01:58 +01:00
---
## Description
<section id='description'>
2020-08-31 14:44:56 -04:00
In JavaScript, you can store a value in a variable with the <dfn>assignment</dfn> operator (<code>=</code>).
2018-09-30 23:01:58 +01:00
<code>myVariable = 5;</code>
This assigns the <code>Number</code> value <code>5</code> to <code>myVariable</code>.
2020-08-31 14:44:56 -04:00
If there are any calculations to the right of the <code>=</code> operator, those are performed before the value is assigned to the variable on the left of the operator.
2019-05-17 06:20:30 -07:00
```js
2020-08-31 14:44:56 -04:00
var myVar;
2019-05-17 06:20:30 -07:00
myVar = 5;
```
2020-08-31 14:44:56 -04:00
First, this code creates a variable named <code>myVar</code>. Then, the code assigns <code>5</code> to <code>myVar</code>. Now, if <code>myVar</code> appears again in the code, the program will treat it as if it is <code>5</code>.
2018-09-30 23:01:58 +01:00
</section>
## Instructions
<section id='instructions'>
Assign the value <code>7</code> to variable <code>a</code>.
</section>
## Tests
<section id='tests'>
```yml
2018-10-04 14:37:37 +01:00
tests:
2019-11-27 02:57:38 -08:00
- text: You should not change code above the specified comment.
2020-08-31 14:44:56 -04:00
testString: assert(/var a;/.test(code));
2019-11-27 02:57:38 -08:00
- text: <code>a</code> should have a value of 7.
2019-07-13 00:07:53 -07:00
testString: assert(typeof a === 'number' && a === 7);
2018-09-30 23:01:58 +01:00
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
// Setup
var a;
// Only change code below this line
```
</div>
### Before Test
<div id='js-setup'>
```js
if (typeof a != 'undefined') {
a = undefined;
}
```
</div>
### After Test
<div id='js-teardown'>
```js
2020-08-31 14:44:56 -04:00
(function(a){return "a = " + a;})(a);
2018-09-30 23:01:58 +01:00
```
</div>
</section>
## Solution
<section id='solution'>
```js
var a;
a = 7;
```
</section>