This file contains hidden or 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
| let beerId = 10; | |
| { | |
| let beerId = 42; | |
| } | |
| console.log(beerId); | |
| // result 12 |
This file contains hidden or 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
| { | |
| let beerId = 42; | |
| } | |
| console.log(beerId) | |
| // result: refrence error |
This file contains hidden or 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
| () => { statements } |
This file contains hidden or 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
| parameter => { statements } |
This file contains hidden or 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
| (firstParameter, secondParameter) => { statements } |
This file contains hidden or 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
| const name = (parameters) => { | |
| statements | |
| } |
This file contains hidden or 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
| var addBeer = function(name, category = 'Pils') { | |
| console.log(name + ' ' + category); | |
| }; | |
| addBeer(); // output: undefined Pils | |
| addBeer('Bitburger'); // output: Bitburger Pils | |
| addBeer('Bolten', 'Alt'); // output: Bolten Alt |
This file contains hidden or 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
| var getBeerPrice = function(price, tax = price * 0.09){ | |
| console.log(price + tax); | |
| }; | |
| getBeerPrice(5); // output: 5.45 |
This file contains hidden or 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
| function sum(…numbers) { | |
| var result = 0; | |
| numbers.forEach(function (number) { | |
| result += number; | |
| }); | |
| return result; | |
| } | |
| console.log(sum(1)); // 1 | |
| console.log(sum(1, 2, 3, 4, 5)); // 15 |
This file contains hidden or 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
| var name = 'Beer'; | |
| var stock = 42; | |
| var product = { | |
| name, | |
| stock, | |
| reduceStock(){ | |
| this.stock--; | |
| } | |
| } |