2018-09-30 23:01:58 +01:00
---
id: 56533eb9ac21ba0edf2244a8
title: Storing Values with the Assignment Operator
challengeType: 1
2020-05-21 17:31:25 +02:00
isHidden: false
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'>
In JavaScript, you can store a value in a variable with the <dfn>assignment</dfn> operator.
<code>myVariable = 5;</code>
This assigns the <code>Number</code> value <code>5</code> to <code>myVariable</code>.
Assignment always goes from right to left. Everything to the right of the <code>=</code> operator is resolved before the value is assigned to the variable to the left of the operator.
2019-05-17 06:20:30 -07:00
```js
myVar = 5;
myNum = myVar;
```
2018-09-30 23:01:58 +01:00
This assigns <code>5</code> to <code>myVar</code> and then resolves <code>myVar</code> to <code>5</code> again and assigns it to <code>myNum</code>.
</section>
## Instructions
<section id='instructions'>
Assign the value <code>7</code> to variable <code>a</code>.
Assign the contents of <code>a</code> to variable <code>b</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.
2019-07-13 00:07:53 -07:00
testString: assert(/var a;/.test(code) && /var b = 2;/.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);
2019-11-27 02:57:38 -08:00
- text: <code>b</code> should have a value of 7.
2019-07-13 00:07:53 -07:00
testString: assert(typeof b === 'number' && b === 7);
2019-11-27 02:57:38 -08:00
- text: <code>a</code> should be assigned to <code>b</code> with <code>=</code>.
2019-07-13 00:07:53 -07:00
testString: assert(/b\s*=\s*a\s*;/g.test(code));
2018-09-30 23:01:58 +01:00
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
// Setup
var a;
var b = 2;
// Only change code below this line
```
</div>
### Before Test
<div id='js-setup'>
```js
if (typeof a != 'undefined') {
a = undefined;
}
if (typeof b != 'undefined') {
b = undefined;
}
```
</div>
### After Test
<div id='js-teardown'>
```js
2018-10-20 21:02:47 +03:00
(function(a,b){return "a = " + a + ", b = " + b;})(a,b);
2018-09-30 23:01:58 +01:00
```
</div>
</section>
## Solution
<section id='solution'>
```js
var a;
var b = 2;
a = 7;
b = a;
```
</section>