L4 - Asynchronous Programming & Interactivity Flashcards

(10 cards)

1
Q

What is a Callback? And what is callback hell?

A

Function passed as argument to another function which is invoked (called back) after a certain task is complete.

Callback hell happens when you have nested callbacks that become hard to read and maintain.
Happens when asynchronous tasks depend on each other in a way that requires deeply nested callbacks

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

Promises

A

Resemble callbacks. Defer processing to some later point whilst other code is executed, then react when we get the event that the promise has completed.

When you call a promise-based asynchronous function, it returns a Promise instance. Only two things can happen to that promise: it can be fulfilled (success) or rejected (failure).

let promise = new Promise((resolve, reject) => {…..});

When result obtained either the resolve or reject callbacks will be called.

.then takes two funcitons

.catch used for error detection

.all - if all promises successful
.any - if any
.race - if the very first one

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

Document interface

A

represents entire webpage (DOM - document Object Model). It provides methods to change HTML and CSS dynamically.

Can get elements by tag, class and id. Can also use document.querySelector().

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

Event handling

A

User or browser interactions that JS can detect and respond to.

e.g. Clicking button, typing in field, hovering, resizing window.

Using event listeners is recommended

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

JQuery

A

Obsolete but was popular when different browsers handled JS inconsistently

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

React

A

Open-source JS library for building UI components. Declarative and component based.

Declarative
- makes code predictable and easier to debug as it auto updates DOM to match components state

Component-based
- can build encapsulated components that manage own state
- Components composed to make complex UIs
- Each component can be reused meaning more manageable code.

  • can be used for web, mobile and desktop apps.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Components

A

Modular and reusable units that form whole UI.

It is a function/class that optionally accepts input and returns a React element, defining how a specific part of UI should be displayed

JSXML used by react

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

JSX

A

React uses JSX to represent markup. Allows you to write HTML-like code inside JS making it easy to create and visualise UI components

RULES
- return single root element
- close all tags
- use camelCase for attributes

Can embed any JS into JSX by wrapping it in {}

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

State

A

JS variable managed by react to store components dynamic state.
State persists across re-renders. When state changes, react auto re-renders to reflect this.

const [state, setState] = useState(initialValue)

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

Props

A

A way to pass data from parent to child component. Makes components reusable and dynamic and allows components to communicate.

Read-only. Props to react is like attributes in html.

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