JS Questions Flashcards

Enhance Knowledge of common JS topics

1
Q

Lexical Scope

A

A variable defined outside of it’s function declaration is accessible by that function

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

Execution Context

A

A stack frame. The current code being executed.

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

Lexing time

A

JS compiles code immediately before execution let a =2 is split to let a (declaration) and a = 2 (instantiation)

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

Currying

A

A function that returns a function

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

How can you do Mutation Avoidance in js

A

Spread operator, object.assign, slice vs splice (slice returns a shallow copy)

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

Define Hoisting

A

moves all declarations to top of execution scope after lexing (splitting declarations vs instantiations) and listing them at the top

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

How does Inheritance work

A

based on prototype chain, goes all the way up to null, prototype has list of methods for that object

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

How does JS do Async

A

The event loop uses the call stack and callback queue to provide asynchronous behavior.

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

List Map vs ForEach differences

A

Map returns a new array. Each execute a function with current element as function arg

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

Function vs arrow() => { …

A

the arrow function isn’t hoisted, arrow is bounded lexically, function is bound execution context

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

List the differences between const let var

A

var is global scoped, const let block scoped (open and closed curly braces). var can be redeclared, const, let cannot. Let can be reassigned.

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

Async iterator

A

await in a for of loop

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

=== vs ==

A

Triple compares type and values. Double compares values.

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

What is Coercion in js?

A

Converts a value to another. E.g. Object to Boolean.

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

What does prototype do?

A

Allows objects to inherit features. Can be used to add features to objects.

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

null vs undefined

A

Null is DNE. Undefined means declared but not instantiated.

17
Q

What are .bind, .call, and .apply used for?

A

Bind sets this to the first param in the function. Call is used to bind this to the scope of the passed object. Apply does the same but takes the arguments as an array.