Front End questions Flashcards
What is React?
React is a JS library used for building interactive user interfaces. It is also the most popular and widely used front-end tool.
What is Javascript?
JS is a scripting language used to create and control dynamic web content. It is synchronous, blocking, and single-threaded in its most basic form. Single-threaded means it can only do one thing at a time.
What is JSX?
An HTML-like syntax extension of Javascript. It allows us to write HTML elements in JS and place them in the DOM without the need of using createElement() and appendChild(). This HTML like synatx is converted into JS objects using a transpiler like Babel
What is the virtual DOM
React creates a Virtual DOM which is a copy of the actual DOM. Any time a change is made or state changes in the application, a new virtual DOM is created and compared to prev virtual DOM. The actual DOM then updates only those objects that were changed in the virtual DOM. Virtual DOM leads to improved performance and faster applications.
What makes Redux special?
Because state is stored in a central location, it makes it easier to understand where errors are occurring thus easier to debug issues. Also, access to Redux dev tools, and handy middlewares like redux thunk and redux persist
What are reducers in redux?
A reducer is a slice of the entire pie that is the application’s state. It is a function that takes in an initial state and a set of various actions. Depending on the action that is dispatched, the state living in the reducer will be altered in a certain manner. The reducer gets exported and imported into the rootReducer which makes up the Redux store.
Why did you choose React?
I chose React because it is a very popular and highly-regarded web technology. Based on my research it seemed to be a less complicated and more beginner friendly JS library/framework, especially when compared to Angular. Moreover it is incredibly powerful due to the various libraries and packages that can be installed to assist you in development.
What is AJAX?
Stands for asynchronous javascript and XML. It is used to make a request to a server in which JSON is the commonly used format for receiving the server data. Fetches are made using XMLHttpRequests. Can use fetch and axios to make AJAX requests which return a promise.
What is Restful API
Restful API simply refers to an API that adheres to the constraints of a REST API.
What is a REST API?
A REST API conforms to a particular set of criteria:
- A client-server architecture in which client requests are made via HTTP. The response format from making this request is typically in JSON (JS Object Notation)
- Stateless communication between client and server. All state is maintained on client side
- Layered system in which the architecture is composed of hierarchical layers that is not visible to the client
What are the major features of React
- Reusable components
- Virtual DOM
- Unidirectional Data flow
- JSX
- Important extensions like Redux for state management and various other useful libraries that make development easier.
What is the DOM?
Document Object Model is a tree-like structure interface that represents how the HTML is read by the browser. It can be manipulated, re-structured, and styled with a scripting language such as JS.
What is State?
State is an object that is used to contain data or information about a specific component. When the user interacts with the page with a particular event, such as a click or key press, the state can change. Depending on the state of the application, the component will behave and render in a certain manner.
What are props?
Props are useful in React in a few ways. One example is when you create a re-usable component in which the structure will be maintained but the content of the component will be different for each instance, props can be used in each occurrence of the component to specify it. Also, if a component is rendering a child component within it, you can give that child component data.
Why do we set a key prop when we map over an array?
The key prop establishes a relationship between the component and the DOM element. It helps React understand which elements should be updated and which can stay in tact after a particular change within the component. It is not recommended to use the item’s index as a key due to the fact that the array can change it’s order at some point.
What is a promise?
A JS object that returns a value which you hope to receive in the future. Promises are well-suited for handling asynchronous operations, such as making a call to an API. 3 states of a promise are pending, fulfilled, rejected. Promise responses can either be handled with .then and .catch method, or by using a try, catch block with async await.
How to make AJAX request using Redux?
install redux thunk which allows asynchronous operations within redux. Create an action that dispatches different types depending on whether the response was resolved or rejected
What is the benefit of using async/await?
Easier to read then .then because you are creating variables for the Promise responses. It looks like synchronous code.
How to copy an array in JS
You can create a new array and use the spread operator to spread all of the values in the existing array to the new array. You can also create a new array in where you map over the existing array and just return the values.
null vs undefined vs undeclared?
- Undeclared means a variable has been declared without the use of var let or const
- Null means the intentional absence of any value.
- Undefined means a variable has been declared but not given a value (let x) or not declared at all
What is a closure?
When a function is defined within another function, the inner function has access to the variables and scope of the outer function even when the outer function has finished executing. The closure is a function that accesses its lexical scope and the variables that live within it even when that function is executed outside its lexical scope. A closure remembers the variables from the place where it is defined, no matter where it is executed.
What is lexical scoping?
It means the accessibility of variables is determined by the position of the variables inside the nested scopes. It means that inside an inner scope you can access variables living in the outer scope.
What does lifting state up mean and why do we do it?
Lifting state from a child component back up to the parent component for the parent to utilize. This is done using a callback function. In other words, you can create a function that alerts the state in the parent and pass this function to the child through props. You can then pass the proper arguments to that function in the child to alter the parent’s state.
What is a callback function?
A callback function is a function that is passed into another function as an argument to be executed later. Common examples include the callback function that is used with an array method such as filter or map, or the function used with a JS eventListener.
What is redux thunk?
It is a Redux middleware that allows you to do async actions by allowing you to return another function in your action which takes dispatch as an argument and then dispatches the synchronous action after the API call has finished.
What is a Redux Middleware?
Redux middleware is a function that sits between the action and reducer and can interact with the dispatched action before reaching the reducer function. Used for purposes such as logging(redux-logger) and asynchronous API calls.