JS Flashcards

1
Q

What is a closure?

A

A closure is an inner function that has access to the outer functions(parent function) variables that are defined in the outer functions scope.

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

What is event delegation?

A

Event delegation is adding event listeners to a parent element instead of to the descendant elements. The listener will fire whenever the event is triggered on the descendant elements due to event bubbling up the DOM

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

Explain the ‘this’ keyword

A

The this keyword is bound to different values based on the context in which it’s called.
With arrow functions, ‘this’ is lexically bound. It uses ‘this’ from the code that contains the arrow function.

If the new keyword is used when calling the function, ‘this’ inside the function is a brand new object.

If apply, call, or bind are used to call/create a function, ‘this’ inside the function is the object that is passed in as the argument.

If a function is called as a method, such as obj.method() — ’this’ is the object that the function is a property of.

If a function is invoked as a free function invocation, meaning it was invoked without any of the conditions present above, this is the global object. In a browser, it is the window object. If in strict mode (‘use strict’), this will be undefined instead of the global object.

If multiple of the above rules apply, the rule that is higher wins and will set the this value.

If the function is an ES2015 arrow function, it ignores all the rules above and receives the this value of its surrounding scope at the time it is created.

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

Explain how prototypal inheritance works

A

When a property is accessed on an object and not found, the JavaScript engine looks at the object’s prototype, and then the prototype’s prototype and so on, until it finds the property defined on one of the prototypes or until it reaches the end of the prototype chain.

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

What is specificity?

A

When the browser decides which CSS property value is most relevant and applies it.
For ex., CSS of an ID overrides CSS
of a class unless !important is used

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

What is Static positioning?

A

Default position, element remains in the natural flow of the page. Top, bottom, left, right, and z-index don’t apply.

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