JavaScript Functions Flashcards
1
Q
HTML Rendering
A
- Reads top to bottom - rendering 1 line at a time.
- As each item is found (image, css, js, etc.) it downloads it.
- While each line is downloaded and rendered it blocks
blocking means that everything else is put on hold until it completes. - JavaScript is downloaded, concatenated into a single file in the order each part is retrieved, global variables declarations and functions are then hoisted, and all the JavaScript is treated as a single script. Statements in the global scope are run as they are loaded preserving the Lexical Order.
2
Q
Anonymous Functions
A
- Anonymous functions have parameters and a code block but do not have a name.
- Can be assigned to variables
- Can use the function keyword:
a. const doubleSum = function (x, y) {
let val = (x + y) * 2;
return val;
}
doubleSum(2, 4);
b. or the the fat arrow operator ( => )
const trippleSum = (x, y) => {
let val = (x + y) * 3;
return val;
} - Equivalent except for this keyword
3
Q
Array forEach() function
A
- Loops through the values in the array 1 at a time, similar to a Java for each.
- Takes an anonymous function as an argument, that function will be passed 3 arguments:
a. Current value
b. index
c. array - Does not return a value