Advanced Concepts Problems Flashcards
All:
https://javascriptweblog.wordpress.com/2010/07/06/function-declarations-vs-function-expressions/
https://javascriptweblog.wordpress.com/2010/07/06/function-declarations-vs-function-expressions/
Hoisting and the var Statement:
https://launchschool.com/lessons/43f23069/assignments/39f50f91
https://launchschool.com/lessons/43f23069/assignments/39f50f91
Strict Mode
Problem at bottom of page
https://launchschool.com/gists/406ba491
https://launchschool.com/gists/406ba491
Closures:
https://launchschool.com/lessons/43f23069/assignments/9362d2cf
https://launchschool.com/lessons/43f23069/assignments/9362d2cf
Private data,
at bottom of page:
https://launchschool.com/lessons/43f23069/assignments/3df10c91
https://launchschool.com/lessons/43f23069/assignments/3df10c91
IIFE
https://launchschool.com/lessons/43f23069/assignments/69bab49c
https://launchschool.com/lessons/43f23069/assignments/69bab49c
Shorthand:
https://launchschool.com/lessons/43f23069/assignments/c6c682cd
https://launchschool.com/lessons/43f23069/assignments/c6c682cd
do this but with no conditional statements
https://launchschool.com/exercises/81b953d7?track=javascript
do this (doesn’t work so good with hidden data)
https://launchschool.com/exercises/d30df1f2?track=javascript
https://launchschool.com/exercises/d30df1f2?track=javascript
Advanced concepts quiz:
https://launchschool.com/quizzes/a669620d
https://launchschool.com/quizzes/a669620d
What does this do?
var foo = 10;
function bar() {
if (foo > 20) {
var foo = 50;
}
console.log(foo);
foo += 10;
}
bar();
bar();
bar();
The declaration for foo on line 5 of the original code gets hoisted to a function-scoped variable, foo, that shadows the foo variable on line 2. Since we’re not initializing the variable inside bar, its value is undefined, and that’s what gets logged each time we execute line 8 in the original code.
function bar() {
var foo;
if (foo > 20) {
foo = 50;
}
console.log(foo);
foo += 10;
}
var foo;
foo = 10;
bar();
bar();
bar();
The following code has console.log calls on lines 1, 4, 8, 10, and 16. In what sequence will those 5 log calls execute? (or not at all?)
console.log(foo());
function foo() {
console.log(‘Waiting for bar!’);
}
function foo() {
console.log(foo);
function bar() {
console.log(‘bar again’);
}
bar();
function bar() {
console.log(‘bar again and again’);
}
}
8 16 1
what does the arguments keyword within a function reference?
An array like object {‘0’: arg1, etc}
Explain in detail what lines 7 and 8 of this code are doing.
let obj = {
foo: ‘foo’,
qux: ‘qux’,
bar: ‘bar’,
};
let obj2 = {…obj};
let { …obj3 } = obj;
On line 7, {…obj} on the right side of the assignment operator uses spread syntax to separate obj into its properties. The brackets that wrap …obj use object literal syntax to create a new object from the properties of the original obj. On the left side of the assignment operator, a new variable called obj2 is declared. The object that was created with object literal syntax is assigned to this new variable. In summary, line 7 made a shallow copy of obj.
On line 8, on the left side of the assignment operator, object destructuring is used to separate the properties of obj. However, the only variable that’s created is using rest syntax to take all of the spread out properties and re-collect them into obj3. Line 8 is also making a shallow copy of obj.
Write a function that takes 5 string arguments, and returns an object with 3 properties:
first: the first argument
last: the last argument
middle: the middle 3 arguments as a sorted array
After writing the function, write some code to call the function. The arguments you provide should come from an array. You should create local variables named first, last, and middle from the return value.
Use shorthand syntax wherever you can
function qux(first, middle1, middle2, middle3, last) {
return {
first,
last,
middle: [middle1, middle2, middle3].sort(),
};
}
let arr = [“Fluffy”, “Pudding”, “Mister”, “Ben”, “Butterscotch”];
let { first, last, middle } = qux(…arr);