Javascript & React Flashcards

1
Q

What is React?

A

React is the most popular javascript library for building user interfaces. Building a component is easier with react as it is reduced to a function that returns HTML elements, called JSX.

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

What is Redux?

A

Redux is a state management library. It means that we can select the data from the state anywhere in the application, as well as perform complex manipulation with it.

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

How does Redux work?

A

it works using predefined actions, which can make different state manipulation. these actions need to be dispatched to the store in order for the state to change.

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

What makes Redux so special?

A

It is more scalable than React context API. Has got a wonderful debugging tool, which can allow going back in time for debugging purposes. Is the best for managing huge chunks of data

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

Redux set up process

A

Create a store and wrap the whole application with it. then you can create different reducers to manipulate different data from the store

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

What are reducers in Redux?

A

In Redux, a reducer is a pure function that takes an action and the previous state of the application and returns the new state. The action describes what happened and it is the reducer’s job to return the new state based on that action.

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

Why do you choose React?

A

reusability, huge community, easy to learn, in demand
- Component-based structure
- Easy learning curve
- Ability to integrate with third-party plugins
- The big community behind it
- Components ready to plug and play into an application

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

What is AJAX?

A

Is the way javascript code makes requests to the server, behind the scenes and receives information in different formats, like JSON and XML

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

What is responsive design?

A

It’s a web development approach that creates dynamic changes to the appearance of a website, depending on the screen size and orientation.

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

What is the difference between REST API and RESTful API?

A

There are no differences between REST and RESTful as far as APIs are concerned. REST is the set of constraints. RESTful refers to an API adhering to those constraints.

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

What is REST API

A

REST is a set of constraints:
- Uniform interface
- Client-server
- Stateless
- Cacheable
- Layered system
- Code on demand (optional)

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

What is closure?

A

an inner function nested inside some parent function has access to the variables (scope) defined in the parent function. (LEXICAL SCOPE)

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

What is a promise?

A

Is an object that represents an asynchronous completion of an operation, either failed or fulfilled

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

What is a callback?

A

a callback is a function passed inside another function as an argument

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

What are the major features of React?

A

It allows you to write custom components and have HTML tags in the form of JSX, hence the code is more maintainable and flexible. Declarative DOM: react takes care to update the UI when changing the state.

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

What is JSX?

A

JSX stands for JavaScript XML. JSX allows us to write HTML in React

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

What is the virtual DOM? How does the virtual DOM work?

A

The virtual DOM is a visual representation of the UI kept in the memory and synced with the real DOM. When the state changes, react takes care of those state changes to be reflected in the DOM. No need to manipulate it manually.

18
Q

state vs props

A

Props are used to pass data from one component to another and are read-only. Whereas state is data storage and it can be changed, but cannot be passed directly to another component, only through props.

19
Q

What does lifting state up mean and why do we do it?

A

Lifting the state up means sharing the data with an ancestor or parent component.

20
Q

Why do we set a key property when we map over an array in React?

A

it gives an unique identifier to each element in the arrat and helps react identify which element was updated, addded or removed.

21
Q

What are the core principles of Redux?

A

(1) it’s a single source of truth for your state. The state is read-only.
(2) The only way to update the state is to dispatch actions, which are objects describing what needs to happen with the state.
(3) Changes are made with pure functions. ( a pure function will always return the same value if the arguments supplied are the same).

22
Q

How do I make an AJAX request using Redux?

A

By creating a promise inside an action.

23
Q

What are the benefits of using Redux DevTools?

A

better debugging experience and the ability to go back in time to check what has happened to the state after a specific step in the code.

24
Q

How do I use React DevTools? What does this help me with?

A

It helps me inspect the component hierarchy. At least that is what I am using it for.

25
Q

What is redux-thunk?

A

Redux Thunk is middleware that allows you to return functions, rather than just actions, within Redux. This allows for delayed actions, including working with promises.

26
Q

React context vs Redux

A
  • Redux is better for huge chunks of dynamic data.,
  • Adding more data with context requires creating another context in react context.
  • In redux logic and state is managed outside the component
  • Whereas context data is managed inside the component, which can become messy.
27
Q

What’s the benefit of using async/await?

A

Increase the performance and responsiveness of your application, particularly when you have long-running operations that do not require blocking the execution. Without async/await the app would be blocked until let’s say the data would be fetched from the server.

28
Q

What is cookie? cookies vs localStorage vs sessionStorage?

A
  • Session storage stores the data only during the session, once the tab is closed, the data gets lost.
  • Cookie is an old storing mechanism with up to 4 kb of storing capacity
  • The localStorage object stores data with no expiration date. The data is not deleted when the browser is closed, and are available for future sessions.
29
Q

What is prototypal inheritance?

A

Simply put, prototypical inheritance refers to the ability to access object properties from another object. We use a JavaScript prototype to add new properties and methods to an existing object constructor. We can then essentially tell our JS code to inherit properties from a prototype.

30
Q

What is the DOM?

A

Is an Interface that allows programs and scripts to dynamically access and update the content, structure, and style of a document.

31
Q

How to copy an Array?

A

Spread operator and all the array methods that return a shallow copy of the array.

32
Q

How to compare two objects?

A
  • Object.is(obj1,obj2)
  • JSON.stringify both objects and compare them.
  • Create an algorithm using object.keys and object.values and use forEach to compare the elements of the object
33
Q

What is asynchronous programming and why is it important in JavaScript?

A

Asynchronous programming is a technique that enables your program to start a potentially long-running task and still be able to be responsive to other events while that task runs, rather than having to wait until that task has finished.

34
Q

What is hoisting?

A

Hoisting is the ability to use a variable or execute a function before it was declared.

35
Q

let, var, const

A

(1) hoisting (var will not show an error when used before declaration, let and const will => but they are both hoisted)
(2) declaration (let a),
(3) scope (block,function)
(4) re-assignment (a=5)

36
Q

what is higher-order function?

A

A higher-order function is a function that takes a function as an argument or returns a function.(map,reduce,filter)

37
Q

What’s the difference between a variable that is: null, undefined or undeclared? How would you go about checking for any of these states?

A

undeclared - can be easily spotted as it will throw an error
null & undefined - are both falsey values
undefined - is declared but has never been assigned a value
null - is a value of a variable which was declared to be empty on purpose

38
Q

What is the difference between a store and a reducer?

A

Store - is what holds all the data your application uses. Reducer - is what manipulates that data when it receives an action.

39
Q

What is the difference between == and ===?

A

=== compares value and type
== compares just the value

40
Q

How do you send data up from child to the parent component?

A

Pass a function as a prop to the Child component. Call the function in the Child component and pass the data as arguments. Access the data in the function in the Parent