- http://www.thatjsdude.com/interview/js2.html#nullVsUndefined
- https://www.toptal.com/javascript/interview-questions
- http://blog.sourcing.io/interview-questions
- https://github.com/mbeaudru/modern-js-cheatsheet
- Use case can include a database connection as the first argument
function curries(fn) {
const args = Array.prototype.slice.call(arguments, 1);
return function() {
return fn.apply(this, args.concat(Array.prototype.slice.call(arguments, 0)));
}
}
const sequence = (start, end) => {
let result = [];
for(let i = start; i <= end; i++) {
result.push(i);
}
return result;
};
let seq5 = curries(sequence, 1);
seq5(5)
(5) [1, 2, 3, 4, 5]
funcDeclaration() {
return 'A function declaration';
}
- Can be overridden, hoisted, shadowed... etc.
const funcExpression = () => {
return 'A function expression';
}
- Closures
- IIFE
const funcGenExpr = function* () => {
yield 42;
};
While the syntax of apply()
is almost identical to that of call()
, the fundamental difference is that call()
accepts an argument list, while apply()
accepts a single array of arguments.
Function.prototype.bind = Function.prototype.bind || function(context){
var self = this;
return function(){
return self.apply(context, arguments);
};
}
- In the global context or inside a function this refers to the window object.
- Inside IIFE (immediate invoking function) if you use "use strict", value of this is undefined. To pass access window inside IIFE with "use strict", you have to pass this.
- While executing a function in the context of an object, the object becomes the value of this
- Inside a setTimeout function, the value of this is the window object.
- If you use a constructor (by using new keyword) to create an object, the value of this will refer to the newly created object.
- You can set the value of this to any arbitrary object by passing the object as the first parameter of bind, call or apply
- For dom event handler, value of this would be the element that fired the event