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
2021-01-13 03:31:00 +01:00
dashedName: storing-values-with-the-assignment-operator
2018-09-30 23:01:58 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
In JavaScript, you can store a value in a variable with the < dfn > assignment</ dfn > operator (`=` ).
`myVariable = 5;`
This assigns the `Number` value `5` to `myVariable` .
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.
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-11-27 19:02:05 +01: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-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --instructions--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
Assign the value `7` to variable `a` .
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --hints--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
You should not change code above the specified comment.
2018-09-30 23:01:58 +01:00
```js
2020-11-27 19:02:05 +01:00
assert(/var a;/.test(code));
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
`a` should have a value of 7.
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(typeof a === 'number' & & a === 7);
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
# --seed--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
## --before-user-code--
2018-09-30 23:01:58 +01:00
```js
if (typeof a != 'undefined') {
a = undefined;
}
```
2020-11-27 19:02:05 +01:00
## --after-user-code--
2018-09-30 23:01:58 +01:00
```js
2020-08-31 14:44:56 -04:00
(function(a){return "a = " + a;})(a);
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
## --seed-contents--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
// Setup
var a;
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
// Only change code below this line
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --solutions--
2018-09-30 23:01:58 +01:00
```js
var a;
a = 7;
```