2018-09-30 23:01:58 +01:00
---
id: 56533eb9ac21ba0edf2244aa
title: Understanding Uninitialized Variables
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/cBa2JAL'
2019-07-31 11:32:23 -07:00
forumTopicId: 18335
2018-09-30 23:01:58 +01:00
---
## Description
< section id = 'description' >
When JavaScript variables are declared, they have an initial value of < code > undefined< / code > . If you do a mathematical operation on an < code > undefined< / code > variable your result will be < code > NaN< / code > which means < dfn > "Not a Number"< / dfn > . If you concatenate a string with an < code > undefined< / code > variable, you will get a literal < dfn > string< / dfn > of < code > "undefined"< / code > .
< / section >
## Instructions
< section id = 'instructions' >
Initialize the three variables < code > a< / code > , < code > b< / code > , and < code > c< / code > with < code > 5< / code > , < code > 10< / code > , and < code > "I am a"< / code > respectively so that they will not be < code > undefined< / 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: < code > a</ code > should be defined and evaluated to have the value of < code > 6</ code > .
2019-07-13 00:07:53 -07:00
testString: assert(typeof a === 'number' & & a === 6);
2019-11-27 02:57:38 -08:00
- text: < code > b</ code > should be defined and evaluated to have the value of < code > 15</ code > .
2019-07-13 00:07:53 -07:00
testString: assert(typeof b === 'number' & & b === 15);
2018-10-04 14:37:37 +01:00
- text: < code > c</ code > should not contain < code > undefined</ code > and should have a value of "I am a String!"
2019-07-13 00:07:53 -07:00
testString: assert(!/undefined/.test(c) & & c === "I am a String!");
2019-11-27 02:57:38 -08:00
- text: You should not change code below the specified comment.
2019-07-13 00:07:53 -07:00
testString: assert(/a = a \+ 1;/.test(code) && /b = b \+ 5;/.test(code) && /c = c \+ " String!";/.test(code));
2018-09-30 23:01:58 +01:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
2020-03-02 23:18:30 -08:00
// Only change code below this line
2018-09-30 23:01:58 +01:00
var a;
var b;
var c;
2020-03-02 23:18:30 -08:00
// Only change code above this line
2018-09-30 23:01:58 +01:00
a = a + 1;
b = b + 5;
c = c + " String!";
```
< / div >
### After Test
< div id = 'js-teardown' >
```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
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
var a = 5;
var b = 10;
var c = "I am a";
a = a + 1;
b = b + 5;
c = c + " String!";
```
< / section >