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
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;
1// JS Variables
2var varExample = "var"; // var is use for variable in js the problem with it that it has complicated scope
3let letExample = "let"; // let is pretty much same as var the only thing which make its more varriable is its variable scope.
4const constExample = "const"; // const is use for constant values and this variable scope is sane as let
1// let & var are both editable variables:
2var cow = 'moo';
3let pig = 'oink';
4cow = 10;
5pig = 10;
6// const is a permanent variable; you cannot change it.
7const uncuttableGrass = '\/\/';
8uncuttableGrass = '___';
9// above throws an error
1// Can be a number
2var myVar = 21
3//Can be a string
4var myVar2 = "string"
5// Used in a function
6function printVar(parvar) {
7 print(parvar);
8}
9
10printVar(myVar2);
11// prints "string"
12printVar(myVar);
13// prints 21
1// 3 ways to create
2
3var mrVariable = 'x'; // You can set it to to a string ( '' ) or no. ( 0 ). It
4// is globally defined
5
6let myVariaible2 = 'y'; // You can set it to string or no. let is block scoped
7
8const myVariable = 'z'; // It is block scoped, can be a string or no. and can't
9//be reassigned