2018-09-30 23:01:58 +01:00
---
id: 56533eb9ac21ba0edf2244aa
title: Understanding Uninitialized Variables
challengeType: 1
2019-02-14 12:24:02 -05:00
videoUrl: 'https://scrimba.com/c/cBa2JAL'
2019-07-31 11:32:23 -07:00
forumTopicId: 18335
2021-01-13 03:31:00 +01:00
dashedName: understanding-uninitialized-variables
2018-09-30 23:01:58 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
When JavaScript variables are declared, they have an initial value of `undefined` . If you do a mathematical operation on an `undefined` variable your result will be `NaN` which means < dfn > "Not a Number"</ dfn > . If you concatenate a string with an `undefined` variable, you will get a literal < dfn > string</ dfn > of `"undefined"` .
# --instructions--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
Initialize the three variables `a` , `b` , and `c` with `5` , `10` , and `"I am a"` respectively so that they will not be `undefined` .
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
`a` should be defined and evaluated to have the value of `6` .
2018-09-30 23:01:58 +01:00
```js
2020-11-27 19:02:05 +01:00
assert(typeof a === 'number' & & a === 6);
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
`b` should be defined and evaluated to have the value of `15` .
```js
assert(typeof b === 'number' & & b === 15);
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
`c` should not contain `undefined` and should have a value of "I am a String!"
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(!/undefined/.test(c) & & c === 'I am a String!');
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
You should not change code below the specified comment.
```js
assert(
/a = a \+ 1;/.test(code) &&
/b = b \+ 5;/.test(code) &&
/c = c \+ " String!";/.test(code)
);
```
# --seed--
## --after-user-code--
2018-09-30 23:01:58 +01:00
```js
2018-10-20 21:02:47 +03:00
(function(a,b,c){ return "a = " + a + ", b = " + b + ", c = '" + c + "'"; })(a,b,c);
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
// Only change code below this line
var a;
var b;
var c;
// Only change code above this line
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
a = a + 1;
b = b + 5;
c = c + " String!";
```
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 = 5;
var b = 10;
var c = "I am a";
a = a + 1;
b = b + 5;
c = c + " String!";
```