8. CALLBACK
• A callback is a function that is to be executed after another
function has finished executing — hence the name ‘call back’.
• In JavaScript, functions are objects. Because of this, functions
can take functions as arguments, and can be returned by other
functions. Functions that do this are called higher-order
functions. Any function that is passed as an argument is called
a callback function.
9. WHY DO WE NEED CALLBACKS?
• JavaScript is an event driven language. This means that instead
of waiting for a response before moving on, JavaScript will keep
executing while listening for other events
12. # OBJECT
• An object is a dynamic collection of properties
• The property key is a unique string. When a non string is used
as the property key, it will be converted to a string. The
property value can be a primitive, object, or function.
• The simplest way to create an object is to use an object literal:
13. OBJECT ACCESS PROPERTY
• There are two ways to access properties: dot notation and
bracket notation. We can read, add, edit and remove an object’s
properties at any time.
• Get : object.name or object[expression]
• Set : object.name = “Tarek” or object[expression] = “Tarek”
• Delete : delete object.name or delete object[expression]
14. OBJECT METHODS
• Object.assign() copies all properties from one object to
another. An object can be cloned by copying all its properties
to an empty object:
• Merging objects
16. OBJECT METHODS
The Object.seal() method seals an object, preventing new properties from being added to
it and marking all existing properties as non-configurable. Values of present properties
can still be changed as long as they are writable.
17. MAP, FOREACH, FILTER, REDUDE
• forEach() -executes a provided function once for each array element. It replace original
object.
• Map() - creates a new array with the results of calling a provided function on every
element in the calling array.
• let arr = [1,2,3,4];
• let plus5 = arr.map((val, i, arr) => {
• return val + 5;
• });
• // plus5 = [5, 7, 8, 9]
• The filter() method returns a new array created from all elements that pass a certain test
preformed on an original array.
• let arr = [1,2,3,4,5,6];
• let even = arr.filter(val => {
• return val % 2 === 0;
• });
• // even = [2,4,6]
• The reduce() method is used to apply a function to each element in the array to reduce
the array to a single value.
• let arr = [1,2,3,4];
• let sum = arr.reduce((acc, val) => {
• return acc + val;