2020-08-31 18:44:56 +00:00
---
id: 5ee127a03c3b35dd45426493
title: Assigning the Value of One Variable to Another
challengeType: 1
videoUrl: ''
forumTopicId: 418265
2021-01-13 02:31:00 +00:00
dashedName: assigning-the-value-of-one-variable-to-another
2020-08-31 18:44:56 +00:00
---
2020-11-27 18:02:05 +00:00
# --description--
2020-08-31 18:44:56 +00:00
After a value is assigned to a variable using the < dfn > assignment< / dfn > operator, you can assign the value of that variable to another variable using the < dfn > assignment< / dfn > operator.
```js
var myVar;
myVar = 5;
var myNum;
myNum = myVar;
```
The above declares a `myVar` variable with no value, then assigns it the value `5` . Next, a variable named `myNum` is declared with no value. Then, the contents of `myVar` (which is `5` ) is assigned to the variable `myNum` . Now, `myNum` also has the value of `5` .
2020-11-27 18:02:05 +00:00
# --instructions--
2020-08-31 18:44:56 +00:00
2020-11-27 18:02:05 +00:00
Assign the contents of `a` to variable `b` .
2020-08-31 18:44:56 +00:00
2020-11-27 18:02:05 +00:00
# --hints--
2020-08-31 18:44:56 +00:00
2020-11-27 18:02:05 +00:00
You should not change code above the specified comment.
2020-08-31 18:44:56 +00:00
2020-11-27 18:02:05 +00:00
```js
assert(/var a;/.test(code) & & /a = 7;/.test(code) & & /var b;/.test(code));
2020-08-31 18:44:56 +00:00
```
2021-03-03 00:12:12 +00:00
`b` should have a value of `7` .
2020-08-31 18:44:56 +00:00
2020-11-27 18:02:05 +00:00
```js
assert(typeof b === 'number' & & b === 7);
```
2020-08-31 18:44:56 +00:00
2020-11-27 18:02:05 +00:00
`a` should be assigned to `b` with `=` .
2020-08-31 18:44:56 +00:00
```js
2020-11-27 18:02:05 +00:00
assert(/b\s*=\s*a\s*/g.test(code));
2020-08-31 18:44:56 +00:00
```
2020-11-27 18:02:05 +00:00
# --seed--
2020-08-31 18:44:56 +00:00
2020-11-27 18:02:05 +00:00
## --before-user-code--
2020-08-31 18:44:56 +00:00
```js
if (typeof a != 'undefined') {
a = undefined;
}
if (typeof b != 'undefined') {
b = undefined;
}
```
2020-11-27 18:02:05 +00:00
## --after-user-code--
2020-08-31 18:44:56 +00:00
```js
(function(a, b) {
return 'a = ' + a + ', b = ' + b;
})(a, b);
```
2020-11-27 18:02:05 +00:00
## --seed-contents--
2020-08-31 18:44:56 +00:00
2020-11-27 18:02:05 +00:00
```js
// Setup
var a;
a = 7;
var b;
2020-08-31 18:44:56 +00:00
2020-11-27 18:02:05 +00:00
// Only change code below this line
```
2020-08-31 18:44:56 +00:00
2020-11-27 18:02:05 +00:00
# --solutions--
2020-08-31 18:44:56 +00:00
```js
var a;
a = 7;
var b;
b = a;
```