Functions
  • Functions are first class objects in JavaScript. They can be assigned, copied or declared in any place of the code.
  • If the function is declared as a separate statement in the main code flow, that’s called a “Function Declaration”.
function add (numOne, numTwo) {
    return numOne + numTwo;
}
  • If the function is created as a part of an expression, it’s called a “Function Expression”.
let subtract = function (numOne, numTwo) {
    return numOne - numTwo;
}
  • Function Declarations are processed before the code block is executed, i.e. declarations are hoisted. They are visible everywhere in the block.
  • Function Expressions are created when the execution flow reaches them.
  • Functions always return something. If there’s no return statement, then the result is undefined.
Objects
  • Use Object.Assign to merge several objects into one. 
let user = { name: "John" };

let permissions1 = { canView: true };
let permissions2 = { canEdit: true };

// copies all properties from permissions1 and permissions2 into user
Object.assign(user, permissions1, permissions2);

// now user = { name: "John", canView: true, canEdit: true }
  • We also can use Object.assign to make a shallow copy of an object.
let user = {
  name: "John",
  age: 30
};

let clone = Object.assign({}, user);
  • To delete a property: 
delete obj.prop
  • To check if a property with the given key exists: 
"key" in obj
  • To iterate over an object: 
for (let key in obj) loop