1// `let` vs `var` vs `const` in 'javascript'
2
3"let" allows you to declare local variable whose scope
4 is limited to the block statement.
5
6"var" allows you to declare a variable globally or locally
7 to an entire function.
8
9"Const" just like let, are block-scoped.
10 It's value can't be reassigned and it can't be redeclared.
11
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 var text = "";
2var i;
3for (i = 0; i < 5; i++) {
4 text += "The number is " + i + "<br>";
5}
1var a;
2console.log(a); // scrive in console "undefined" o "" a seconda del browser usato.
3console.log('still going...'); // scrive in console "still going...".