For help with markdown syntax Go here
- The forEach method iterates over the items in an array and applies ot each, one by one. Also, forEach accomplishes a similiar execution as a for loop. The .map method actually transforms each item in an array, then returns a new array of the items with the same size.
2. Name five different Types in JavaScript. A Type is something that can represent data. What is so special about Arrays?
- An array is a special variable that can hold more than one value at a time. You can think of it as a list of items/elements. Their elements are stored as object properties, using the array index as the property name.
- Closure is created whenever you declare a function within another function. The outer function's scope becomes accessible within the inner function.
function init() {
var name = 'Mozilla'; // name is a local variable created by init
function displayName() { // displayName() is the inner function, a closure
alert(name); // use variable declared in the parent function
}
displayName();
}
init();