2018-09-30 22:01:58 +00:00
---
id: bd7123c9c444eddfaeb5bdef
title: Declare String Variables
challengeType: 1
2019-02-14 17:24:02 +00:00
videoUrl: 'https://scrimba.com/c/c2QvWU6'
2019-07-31 18:32:23 +00:00
forumTopicId: 17557
2021-01-13 02:31:00 +00:00
dashedName: declare-string-variables
2018-09-30 22:01:58 +00:00
---
2020-11-27 18:02:05 +00:00
# --description--
2018-09-30 22:01:58 +00:00
2021-10-25 16:55:58 +00:00
Previously you used the following code to declare a variable:
```js
var myName;
```
But you can also declare a string variable like this:
2018-09-30 22:01:58 +00:00
2021-03-25 21:07:48 +00:00
```js
var myName = "your name";
```
2018-09-30 22:01:58 +00:00
2021-10-25 16:55:58 +00:00
`"your name"` is called a < dfn > string</ dfn > < dfn > literal</ dfn > . A string literal, or string, is a series of zero or more characters enclosed in single or double quotes.
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
# --instructions--
2018-09-30 22:01:58 +00:00
2021-03-03 00:12:12 +00:00
Create two new string variables: `myFirstName` and `myLastName` and assign them the values of your first and last name, respectively.
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
# --hints--
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
`myFirstName` should be a string with at least one character in it.
2018-09-30 22:01:58 +00:00
```js
2020-11-27 18:02:05 +00:00
assert(
(function () {
if (
typeof myFirstName !== 'undefined' & &
typeof myFirstName === 'string' & &
myFirstName.length > 0
) {
return true;
} else {
return false;
}
})()
);
```
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
`myLastName` should be a string with at least one character in it.
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
```js
assert(
(function () {
if (
typeof myLastName !== 'undefined' & &
typeof myLastName === 'string' & &
myLastName.length > 0
) {
return true;
} else {
return false;
}
})()
);
2018-09-30 22:01:58 +00:00
```
2020-11-27 18:02:05 +00:00
# --seed--
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
## --after-user-code--
2018-09-30 22:01:58 +00:00
```js
2018-10-20 18:02:47 +00:00
if(typeof myFirstName !== "undefined" & & typeof myLastName !== "undefined"){(function(){return myFirstName + ', ' + myLastName;})();}
2018-09-30 22:01:58 +00:00
```
2020-11-27 18:02:05 +00:00
## --seed-contents--
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
```js
2021-03-03 21:14:28 +00:00
2020-11-27 18:02:05 +00:00
```
2018-09-30 22:01:58 +00:00
2020-11-27 18:02:05 +00:00
# --solutions--
2018-09-30 22:01:58 +00:00
```js
var myFirstName = "Alan";
var myLastName = "Turing";
```