Functions Flashcards
does all functions return a value?
Yes, by default it is undefined…. if the function return something, then it might be anything else.
How to access an argument of a function that does not declare any parameter?
via arguments[]
What is an Immediately Invoked Function Expression (IIFE)? How to declare it?
it is a function that is called right after declared. Declared via:
(function () {code here}();
What is a Closure?
It is when the function returns a function. e.g:
function sum(a, b) { return function suminternally() { return a+b; } }
let mysum = sumb(1,2); mysumn(); //returns 3
When Arrow Functions were introduced?
ES6
Why using arrow functions?
Shorter syntax
How to declare an arrow function with and without params?
let af = param => {return param }; af('asd') // returns 'asd'
let af = () => {return 'asd'}; af() // returns 'asd'
How to declare an arrow function that takes two or more params?
let af = (a, b) => {return a+b}
Are arrow functions similar to c#’s lambda expressions?
Yes, same thing but with different names
what happens to the this keyword when using arrow functions?
They are available but with a different scope (not the object scope). it is likely to be the Window object.