Skip to content

Instantly share code, notes, and snippets.

View SaschaHeyer's full-sized avatar
👨‍🚀

Sascha Heyer SaschaHeyer

👨‍🚀
View GitHub Profile
@SaschaHeyer
SaschaHeyer / blockscoping.js
Last active February 28, 2018 10:58
blockscoping.js
let beerId = 10;
{
let beerId = 42;
}
console.log(beerId);
// result 12
@SaschaHeyer
SaschaHeyer / blockscoping2.js
Last active February 28, 2018 10:58
blockscoping2.js
{
let beerId = 42;
}
console.log(beerId)
// result: refrence error
@SaschaHeyer
SaschaHeyer / arrowParameterZero.js
Created February 27, 2018 17:47
arrowParameterZero
() => { statements }
@SaschaHeyer
SaschaHeyer / arrowParameterOne.js
Created February 27, 2018 17:48
arrowParameterOne
parameter => { statements }
@SaschaHeyer
SaschaHeyer / arrowParameterMore.js
Last active February 28, 2018 13:10
arrowParameterMore.js
(firstParameter, secondParameter) => { statements }
@SaschaHeyer
SaschaHeyer / arrowFunction.js
Created February 27, 2018 17:50
arrowFunction
const name = (parameters) => {
statements
}
@SaschaHeyer
SaschaHeyer / defaultFunctionParamters.js
Last active March 1, 2018 09:03
defaultFunctionParamters
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
@SaschaHeyer
SaschaHeyer / defaultFunctionParamters.js
Last active March 1, 2018 09:04
defaultFunctionParamters
var getBeerPrice = function(price, tax = price * 0.09){
console.log(price + tax);
};
getBeerPrice(5); // output: 5.45
@SaschaHeyer
SaschaHeyer / restParameter.js
Last active February 27, 2018 18:57
restParameter
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
@SaschaHeyer
SaschaHeyer / objectLiteralExtensions.js
Last active February 28, 2018 10:55
objectLiteralExtensions
var name = 'Beer';
var stock = 42;
var product = {
name,
stock,
reduceStock(){
this.stock--;
}
}