Javascript Flashcards

1
Q

Currying

A

In relation to Functional JS

aka partial application is a functional programming technique.

Advantages: makes js more readable

Currying is a way of constructing functions such that you can provide the arguments required for a the function in parts rather than all at once.

When you give a piece you receive back a function that is waiting for the rest of the arguments.

ex:

var greetCurried = function(greeting) {
return function(name) {
console.log(greeting + “, “ + name);
};
};
~~~
note you can pass the entire thing like this:
greetCurried(“Hi there”)(“Howard”); //”Hi there, Howard”
~~~

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

What is jQuery?

A

jQ is a javascript library that offers shortcut methods for interaction with the DOM.

Things like HTML document traversing, event handling, animation, and Ajax interactions.

Note that jQuery is not a language! It’s js.

Cons: jQuery can be slow due to multiple DOM manipulatiopns (considered expensive). Also for animations css can be faster due to browser-side transitions (also written in c++).

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

Promises

A

A promise represents the result of an asynchronous operation. It acts as a placeholder where the eventual return value (or error) will materialize.

Promises are a simpler alternative to executing complex callbacks for managing asynch tasks.

Promises have 3 states:

1) Pending
2) Fulfilled: returns some value
3) Rejected: (activates error/ returns “reason” for fail)

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

Javascript Closures

A

Inner functions in js always have access to the variables and parameters in the outer function and global scope. This is true even after the outer function has returned.

Closures also store REFERENCE to outer function’s variables. (not the actual variable)

This can be a powerful tool as long as you are aware that the closure will use the CURRENT value for the “enclosed” variables.

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

What is hoisting?

A

Hoisting is the JavaScript interpreter’s action of moving all variable and function declarations to the top of the current scope. However, only the actual declarations are hoisted. Any assignments are left where they are.

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

How can you empty an array in js

A
  1. while loop to pop each
  2. reassign to [] (won’t work for const)
  3. Array.splice(0)
  4. Array.length = 0
How well did you know this?
1
Not at all
2
3
4
5
Perfectly