-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Emmanuel (Manu) Enzeyi
authored
Oct 29, 2023
1 parent
55a7bb1
commit 7a21e2c
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
|
||
# Variables In JavaScript | ||
|
||
|
||
We can easily describe variables as containers for storing data. | ||
|
||
There are several ways through which we can define variables in javascript; either automatically or by using the var, let or const keywords. | ||
|
||
Let us have a look at some examples: | ||
|
||
## Automatic Declaration | ||
In this case, the variables will get declared as variables automatically: | ||
|
||
|
||
```bash | ||
//Creating a variable named x and storing the value 20 in it | ||
x=20; | ||
|
||
//creating a variable named y and storing the value 30 in it | ||
y=30; | ||
|
||
//creating the variable z and storing the sum of variable x and variable y in it | ||
z=x+y; | ||
``` | ||
## Declaration using the var keyword | ||
|
||
In this case we are using the var keyword | ||
|
||
```bash | ||
//Creating a variable named myAge using the var keyword and storing the value 27 in it | ||
|
||
var myAge=27; | ||
``` | ||
|
||
## Declaration using the let keyword | ||
|
||
```bash | ||
//Creating a variable named herAge using the let keyword and storing the value 25 in it | ||
|
||
let herAge=25; | ||
``` | ||
## Declaration using the const keyword | ||
|
||
```bash | ||
//Creating a variable named myAge, herAge and OurTotalAge and storing the sum of variable herAge and myAge in the variable OurTotalAge | ||
|
||
const herAge=25; | ||
const myAge=27; | ||
const OurTotalAge=herAge+myAge; | ||
|
||
``` | ||
|
||
|