JavaScript Concepts Flashcards

1
Q

In JavaScript, what is an isomorphic application?

A

An isomorphic application (aka Universal JavaScript) means that the application can run both on the server and on the client. This can be used to render on the server so that the client can display the content more or less immediately.

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

What is hoisting in JavaScript?

A

During the compilation phase of JavaScript execution, keywords (var, let, const, function, class) are allocated locations in memory.

If not assigned an explicit value, declarations with the var keyword also initialized and assigned the value “undefined.” During the execution phase, var-declared variables are available to the parser anywhere within the function scope (if declared within a function) or at the global level if declared outside a function.

All that means that a variable referenced lexically prior to its own declaration is valid and will be executed without error.

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

What is the difference between var, let, and const?

A

All are reserved keywords used for declaring variables.

var: the var keyword declares and initializes a variable at the top of its function scope (or in the global scope if declared outside a function).

let and const, on the other hand, declare block-scoped variables (i.e., anything within curly braces { } ). In a sense, variables declared with let and const are also “hoisted” (in that they are allocated space in memory during the compilation phase), but they are not initialized until execution—with var you get “undefined”; with let/const you get “X is not defined.”

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

What is the practical difference between let and const?

A

const: const-declared variables cannot have their base value type overwritten.

  • For example, if you declare an object using const (e.g., const myObj = {}), myObj can never be changed to an array, a string, a boolean, a number, etc.*
  • The properties of myObj can be added to, altered, or removed, by myObj will forever remain an object.*

let: variables declared with let can be changed and updated as needed (for example, during iterations).

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

What are the basic hooks available in ReactJS?

A

useEffect - Accepts a function that contains imperative, possibly effectful code.

useState - Returns a stateful value, and a function to update it.

useContext - Accepts a context object (the value returned from React.createContext) and returns the current context value for that context. The current context value is determined by the value prop of the nearest above the calling component in the tree.

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

What are the three main phases of the React component lifecycle?

A
  1. Mounting
  2. Updating
  3. Unmounting
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the useReducer hook?

A

An alternative to useState. Accepts a reducer of type (state, action) => newState, and returns the current state paired with a dispatch method. (If you’re familiar with Redux, you already know how this works.)

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

What are the most common React component lifecycle methods?

No. 1

A
  1. Constructor() - needed to…
  • Set initial values for state
  • Bind the keyword “this” to refer to the current object in non-lifecycle methods
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the most common React component lifecycle methods?

No. 2

A
  1. render()
    * Renders component to the UI
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the React component lifecycle methods?

No. 3

A
  1. componentDidMount( )

Triggered automatically after a component is successfully mounted and rendered for the first time. Often used to fetch application data.

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

What are the React component lifecycle methods?

No. 4

A
  1. componentDidUpdate( )

Triggered automatically after a component is successfully updated.

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

What are the React component lifecycle methods?

No. 5

A
  1. componentWillUnmount( )

Triggered automatically right before the component is unmounted and destroyed.

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

What are the three types of scope in JavaScript?

A
  1. Global - variables and expressions declared outside of a function have global scope (even when declared with let or const)
  2. Function (or Local) - variables and expressions can only be accessed from within the function
  3. Block (via let and const in es6) -
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the three types of scope in JavaScript?

A
  1. Global - variables and expressions declared outside of a function have global scope (even when declared with let or const)
  2. Function (or Local) - variables and expressions can only be accessed from within the function
  3. Block (via let and const in es6) -
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

True or False

In “Strict Mode” undeclared variables are automatically global in scope.

A

False.

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

What is the definition of scope in JavaScript (according to MDN)?

A

The current context of execution. The context in which values and expressions are “visible” (aka available) and can be successfully referenced. If a variable or expression is not “in the current scope,” it is unavailable for use.

17
Q

What are the different categories of HTTP headers?

A
  1. Request headers - contain information about requested resource or about the client itself
  2. Response headers - contain information about the response or about the server doing the responding
  3. Representation headers - contain information about the response body (MIME type, for example) or about applied encoding and/or compression
  4. Payload headers - contain representation-independent information about the payload data (e.g., its length, its transport encoding)
18
Q

Why is scope important?

A
  1. Ownership. Scope limits what parts of the app can change/interact with other parts of the code.
  2. Avoiding name collisions. Without clear boundaries, all variables would need to have unique names. This is impractical and undesirable. Scope boundaries prevent collisions. Imagine having to come up with a unique name for every iterator in every for loop.
  3. Garbage collection. Cleary-defined scopes allow the JavaScript compiler to know where and when to perform garbage collection
19
Q

What are the different categories of HTTP headers?

A
  1. Request headers - contain information about requested resource or about the client itself
  2. Response headers - contain information about the response or about the server doing the responding
  3. Representation headers - contain information about the response body (MIME type, for example) or about applied encoding and/or compression
  4. Payload headers - contain representation-independent information about the payload data (e.g., its length, its transport encoding)
20
Q

What are some ways to make your components more reusable/sharable?

A
  1. Keep UI logic and feature-specific logic separate; should never be bound together
  2. Pass mandatory params by name, but also allow for extended props (object)
  3. The component should be flexible—agnostic about where it may end up. Host parent can implement restraints as necessary
  4. Keep the component as dumb as possible, push logic upwards whenever possible
  5. Allow for easy style overrides (except as dictated by a common design language)
21
Q

What are some disadvantages of css-in-js?

A
  1. Learning curve
  2. Added complexity (may not be worth the hassle)
  3. Less readable code
  4. Potential performance hit (if your components pull in external CSS dependencies, or if there’s a lot of css-in-js since JS is slower to parse than CSS)
22
Q

What are the advantages of css-in-js (with libraries like Styled Components, Linaria, or Emotion)?

A
  1. Local scoping.
  2. Independence. Component can run on its own without reliance on an external stylesheet
  3. Encapsulation. Expose the API, hide implementation details
  4. Portability.
  5. Dynamic functionality. Add complex JS logic to your styles.
  6. Potential performance gains as over against a traditionally-loaded external stylessheet.
23
Q

What are the steps in HTTP request-response life cycle?

A
  1. User inputs or generates an information query
  2. Client forms a Request message with any necessary request headers and sends specified request to the server
  3. Server interprets the request, uses a route handler to do a DB lookup, generates a response message and sets response status
  4. Client uses representational and any payload headers to parse the data correctly (assuming a successful response)
  5. Client renders new data to a data structure or the UI or whatever
24
Q

What are the three main components of the HTTP protocol?

A
  1. User-agent: Any mechanism that acts on behalf of the user—most commonly, a web browser
  2. Web server: Serves information to fulfill the requests of the user-agent.
  3. Proxies: An intermediary between the user-agent and the web server (perform things like caching, filtering, load balancing, authentication, logging).
25
Q

What are the constituent parts of a URL?

A

Protocol → domain name → path to resource → optional query string

protocol//:domainName/path/to/resource?queryString=’’

26
Q

What does URL stand for?

A

Unique Resource Locator

27
Q

What are the broad categories of HTTP responses (by numbers)

A

200s - successful request

300s - redirect of some sort

400s - Problem on the client

500s - Problem on the server