Skip to content

Instantly share code, notes, and snippets.

View Fouzyyyy's full-sized avatar

Faouzi Medebbeb Fouzyyyy

  • Munich, Germany
View GitHub Profile
@Fouzyyyy
Fouzyyyy / this-variable-in-arrow-functions.js
Last active October 14, 2017 22:06
This variable in arrow functions
var obj = {foo: 'foo', bar: 'bar'};
function func() {
// IIFE!
(() => {
console.log(this);
})();
}
let boundFunc = func.bind(obj);
@Fouzyyyy
Fouzyyyy / before-after.js
Last active October 14, 2017 18:59
Before and after
// Before
let multiplyByItself = (number) => {
return number * number;
};
// After
let multiplyByItself = number => number * number;
@Fouzyyyy
Fouzyyyy / arrow-function-with-a-single-return-statement.js
Created October 14, 2017 18:53
Arrow function with a single return statement
let multiplyByItself = number => number * number;
alert(multiplyByItself(2)); // 4
@Fouzyyyy
Fouzyyyy / arrow-function-with-no-parentheses.js
Last active October 14, 2017 18:47
Arrow function with no parentheses
// The number parameter does not need to be surrounded by parentheses
let multiplyByItself = number => {
return number * number;
};
alert(multiplyByItself(2)); // 4
@Fouzyyyy
Fouzyyyy / arrow-function-user-age-message.js
Created October 14, 2017 18:20
Arrow function with one argument v1
// The simplest way
let multiplyByItself = (number) => {
return number * number;
};
alert(multiplyByItself(2)); // 4
@Fouzyyyy
Fouzyyyy / arrow-function-as-callable.js
Created October 14, 2017 15:31
Arrow functions as callable parameters
function executeThis(callableParameter) {
callableParameter();
alert('We are done here :)');
}
executeThis(() => {
alert('Hi there! I am an arrow function passed as an argument, ihaaaaaaa!');
});
@Fouzyyyy
Fouzyyyy / arrow-functions-currency-converter.js
Created October 14, 2017 15:15
Arrow functions: currency converter
// At the time of this writing, 1 US dollar = 0.85 Euro
const euro = 0.85;
let dollarsToEuros = (dollars) => {
if (dollars == 0) {
return 0;
} else {
return dollars * euro;
}
@Fouzyyyy
Fouzyyyy / arrow-function-is-a-function-expression.js
Last active October 14, 2017 14:36
An arrow function is a function expression!
// We can do this
let bar = (arg) => {
console.log('hi ' + arg + ', nice to meet you!');
};
// But we can't do that!
function bar(arg) => {
console.log('hi ' + arg + ', nice to meet you!');
}
@Fouzyyyy
Fouzyyyy / arrow-function-description.js
Last active October 14, 2017 13:54
Arrow functions description
function foo(arg) {
console.log('hi ' + arg + ', nice to meet you!');
}
// VS
let bar = (arg) => {
console.log('hi ' + arg + ', nice to meet you!');
};