Advanced Concepts Problems Flashcards

1
Q

All:
https://javascriptweblog.wordpress.com/2010/07/06/function-declarations-vs-function-expressions/

A

https://javascriptweblog.wordpress.com/2010/07/06/function-declarations-vs-function-expressions/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Hoisting and the var Statement:
https://launchschool.com/lessons/43f23069/assignments/39f50f91

A

https://launchschool.com/lessons/43f23069/assignments/39f50f91

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Strict Mode
Problem at bottom of page
https://launchschool.com/gists/406ba491

A

https://launchschool.com/gists/406ba491

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Closures:
https://launchschool.com/lessons/43f23069/assignments/9362d2cf

A

https://launchschool.com/lessons/43f23069/assignments/9362d2cf

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Private data,
at bottom of page:
https://launchschool.com/lessons/43f23069/assignments/3df10c91

A

https://launchschool.com/lessons/43f23069/assignments/3df10c91

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

IIFE
https://launchschool.com/lessons/43f23069/assignments/69bab49c

A

https://launchschool.com/lessons/43f23069/assignments/69bab49c

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Shorthand:
https://launchschool.com/lessons/43f23069/assignments/c6c682cd

A

https://launchschool.com/lessons/43f23069/assignments/c6c682cd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

do this but with no conditional statements

A

https://launchschool.com/exercises/81b953d7?track=javascript

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

do this (doesn’t work so good with hidden data)
https://launchschool.com/exercises/d30df1f2?track=javascript

A

https://launchschool.com/exercises/d30df1f2?track=javascript

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Advanced concepts quiz:
https://launchschool.com/quizzes/a669620d

A

https://launchschool.com/quizzes/a669620d

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does this do?
var foo = 10;

function bar() {
if (foo > 20) {
var foo = 50;
}

console.log(foo);
foo += 10;
}

bar();
bar();
bar();

A

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();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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’);
}
}

A

8 16 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what does the arguments keyword within a function reference?

A

An array like object {‘0’: arg1, etc}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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;

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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

A

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);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly