- You can use bind to partially apply arguments to functions.
function map(cb, arr) {
return arr.map(cb);
}
const superMap = map.bind(null, (item) => 'super ' + item);
superMap([1,2,3]);
// output: ["super 1", "super 2", "super 3"]
- You can use destructuring to find the length of an array
const {length} = [1,2,3];
console.log(length);
// output: 3
- Functions expressions and arrow functions aren't hoisted — only function declarations are.
add(1, 2);
// TypeError: add is not a function
// Function expression
var add = function(a, b) {
return a + b;
}
// Arrow function
var add = (a, b) => a + b;
In the example above, the variable name add will be hoisted. But it will be assigned the value of undefined
until a function is assigned to it.