Files

39 lines
1008 B
Markdown
Raw Normal View History

2018-10-12 15:37:13 -04:00
---
title: Declare JavaScript Variables
---
# Declare JavaScript Variables
---
## Hints
### Hint 1
2018-10-12 15:37:13 -04:00
When we store data in a data structure, we call it a variable. JavaScript variables are written in camel case. An example of camel case is: `camelCase`.
You can declare a variable this way
```js
var myName = "Rafael";
2018-10-12 15:37:13 -04:00
```
ES6 introduced two other ways to declare variables. __let__ and __const__. _Let_ is pretty similar to var and for the most part is interchangeable:
```js
let myAge = 36;
2018-10-12 15:37:13 -04:00
```
Where _let_ differs, is in its scope. When we declare using _var_, it's global in scope. When we declare using _let_, the scope is limited to that function. If you want to use a _let_ variable outside a function, you have to make it global in scope or redeclare it in the next function.
__const__, on the other hand, can only be declared once. Its value can never change.
---
## Solutions
<details><summary>Solution 1 (Click to Show/Hide)</summary>
```js
const myName = "Christina";
2018-10-12 15:37:13 -04:00
```
</details>