1//choose the best for your solution
2var myVariable = 22; //this can be a string or number. var is globally defined
3
4let myVariable = 22; //this can be a string or number. let is block scoped
5
6const myVariable = 22; //this can be a string or number. const is block scoped and can't be reassigned
1var Number = 5;
2var String = "Hi!";
3var boolen1 = true;
4var boolen2 = false;
5var array = [11, "Hi!", true];
6var object = {age:11, speach:"Hi!", likes_Bananas:true};
1 var text = "";
2var i;
3for (i = 0; i < 5; i++) {
4 text += "The number is " + i + "<br>";
5}
1//Making variables with let:
2let numberOfFriends = 1;
3
4//Incrementing:
5numberOfFriends += 3; //numberOfFriends is now 4
6
7// Variables with const
8const minimumAge = 21; //CANNOT REASSIGN!
9
10//Booleans - true or false values
11true;
12false;
13let isHappy = true;
14
15//Naming Conventions
16// Use upper camel-cased names:
17let numberOfChickens = 6; //GOOD
18// NOT THE JS WAY:
19// let number_of_chickens = 6;
1var user_name = prompt("Please enter your name:", "Type here");
2alert("Hello " + user_name);
1//You can make a variable by using:
2var variable-name = 'defenition of the variable';
3// Or you can use
4let variable-name = 'defenition of the variable';