For help with markdown syntax Go here
- Describe the differences between
.forEachandmap.
- The difference is that
mapreturns a new array and.forEachdoesn't..forEachjust operates all all values in the orginal array.
- Name five different types in JavaScript. What is so special about Arrays?
- The five different types in JavaScript are:
- object is an object is a value in memory which is referenced by an identifier. It associates a key with a value.
- boolean represents a logicale entity and can have two values of true or false.
- number is an numerical integer that has floating points.
- string represents texual data and is enclosed with "" or ''. The indexes are zero based also.
- undefined is a variable that has not been assigned a value yet. It is not the same as
nullornot definded.
- An array can hold many values under a single name, and you can access the values by referring to an index number.
- What is closure? Can you code out a quick example of a closure?
- A closure is an inner function that has access to the outer (enclosing) function's variables—scope chain. The closure has three scope chains: it has access to its own scope (variables defined between its curly brackets), it has access to the outer function's variables, and it has access to the global variables
- example:
function inIt() {
const name = "Mark"; // created local variable name
function displayName() { // closure happens here at inner function
console.log(name); // use variable declared in parent function
}
displayName();
}
inIt();
- Describe the four rules of the 'this' keyword.
- The four rules of the
thiskeyword are:
- Whenever a function is contained in the global scope, the value of
thisinside of that function will be the window object. - When a function is called by a preceding dot, the object before the dot is
this. - Whenever a construction function is used,
thisrefers to the specific instance of the object that is created and returned by the constructor function. - Whenever JavaScipt's
callorapplymethod is used,thisis explicitly defined.