FE interview Flashcards
What is React?
An open-source JavaScript library developed by Facebook. It’s used for building interactive user interfaces and web applications quickly and efficiently with significantly less code in comparison with vanilla JavaScript.
In React, you develop your applications by creating reusable components that you can treat as independent blocks.
It supports reusable components, cutting down development time.
It uses JSX that makes it easier to code and render elements.
Also it uses Virtual DOM that eliminates excessive re-rendering, ensuring the high performance of your application.
What is Redux?
Redux is an open-source JavaScript library for managing and centralizing application state.
It’s required to share data across the application and avoid props drilling.
The main advantage of using Redux is that it provides a predictable way to manage state in the application.
By making all state changes go through a central store, it’s easier to understand how the application’s state is modified.
What are 3 main concepts of Redux?
How does Redux work?
Redux has three main concepts:
The store:
This is the single source of truth for the application’s state. It’s a big object that contains the current state of the application, and the central place where all state changes are made.
Actions:
Actions are objects that indicate an intention to change the state of the application. Actions get dispatched to the store. From there, the store uses them to determine how to update its state.
Reducers:
Reducers are pure functions. They take in the current state of the store and an action, and return a new state. They’re responsible for updating the store’s state. They use actions as information to do this. The Redux state should never be modified directly.
Where is Redux stored
Redux keeps the state of the entire application in a single object, called the store. This store is a JavaScript object that provides methods for updating that state. The Redux store is created using the createStore function from the Redux library.
What makes Redux so special?
The main advantage of using Redux is that it provides a predictable way to manage state in your application.
By making all state changes go through a central store, it’s easier to understand how the application’s state is modified.
Having this single source of truth makes it much easier to debug any issues.
It’s also easier to test, and to reset the store to a known initial state.
When using Redux with React, we can also manage state for React components. This makes it easier to build more complex, interactive applications.
Using Redux also gives a clear way to access and update the state of individual components.
Redux set up process
Install the Redux library.
Create a store using the createStore function from the Redux library. We will pass the store a reducer function. This is a pure function that takes in the current state of the store and an action, and returns a new state.
Dispatch actions to the store using the dispatch method and passing it an action object. The store will use the reducer function to update its state based on the action that was dispatched.
Why do you choose React?
React allows developers to utilize individual parts of their application, which boosts the speed of the development process. In simple terms, different developers can write individual parts and these changes will not cause the logic of the application.
It makes JavaScript coding more simple
It supports reusable components, cutting down development time.
JSX makes it easier to code and render elements.
Virtual DOM eliminates excessive re-rendering, ensuring the high performance of your application.
What is AJAX?
AJAX = Asynchronous JavaScript And XML.
AJAX is not a programming language.
AJAX just uses a combination of: A browser built-in XMLHttpRequest object (to request data from a web server)
AJAX is an acronym for Asynchronous JavaScript and XML. It is a group of inter-related technologies like JavaScript, DOM, XML, HTML/XHTML, CSS, XMLHttpRequest etc.
AJAX allows to send and receive data asynchronously without reloading the web page. So it is fast.
AJAX allows to send only important information to the server not the entire page. So only valuable data from the client side is routed to the server side. It makes the application interactive and faster.
What is responsive design?
Responsive Web Design is about using HTML and CSS to automatically resize, hide, shrink, or enlarge, a website, to make it look good on all devices (desktops, tablets, and phones)
What is Restful API?
RESTful API is an interface that two computer systems use to exchange information securely over the internet.
REST API is nothing but an application programming interface that follows REST architectural constraints such as statelessness, cacheability, maintainability, and scalability.
What is the difference between REST API and RESTful API?
The REST API follows all the rules of the REST Architecture. It has a client-server, stateless, cacheable, layer system with a uniform interface, whereas the RESTful web applications have all the features of the REST architecture with unique additional features
REST (REpresentational State Transfer) is basically an architectural style of development having some principles:
It should be stateless
It should access all the resources from the server using only URI
It does not have inbuilt encryption
It does not have session
It uses one and only one protocol - HTTP
For performing CRUD operations, it should use HTTP verbs such as get, post, put and delete
It should return the result only in the form of JSON or XML, atom, OData etc. (lightweight data )
REST based services follow some of the above principles and not all
RESTFUL services means it follows all the above principles.
What is the point of RESTful API?
RESTful APIs are the most commonly used APIs in the world of web services. They use Hypertext Transfer Protocol (HTTP) requests to create, read, update, and delete (CRUD) data. They are popular because of their simplicity, scalability, speed, and ability to handle all data types.
What is a promise?
Promises are used to handle asynchronous operations in javascript
Before promises, callbacks were used to handle asynchronous operations. But due to the limited functionality of callbacks, using multiple callbacks to handle asynchronous code can lead to unmanageable code.
Promise object has four states -
Pending - Initial state of promise. This state represents that the promise has neither been fulfilled nor been rejected, it is in the pending state.
Fulfilled - This state represents that the promise has been fulfilled, meaning the async operation is completed.
Rejected - This state represents that the promise has been rejected for some reason, meaning the async operation has failed.
Settled - This state represents that the promise has been either rejected or fulfilled. A promise is created using the Promise constructor which takes in a callback function with two parameters, resolve and reject respectively.
What is a callback?
Callbacks are functions that can be passed as an argument to another function. The callback function can be called from the function to which it was passed after some event has happened. Usually used for asynchronous actions
What are the major features of React?
JSX.
Components.
One-way Data Binding.
Virtual DOM.
Simplicity.
Performance.
What is JSX?
JSX stands for JavaScript syntax extension. It is a JavaScript extension that allows us to describe React’s object tree using a syntax that resembles that of an HTML template. It is just an XML-like extension that allows us to write JavaScript that looks like markup and have it returned from a component.
What is the virtual DOM
a concept used in react to provide faster updates on the DOM, React keeps in memory a copy of DOM, whenever there is an update React updates virtual DOM and sync it with real DOM
How does the virtual DOM work?
The virtual DOM is only a virtual representation of the DOM. Every time the state of our application changes, the virtual DOM gets updated instead of the real DOM.
React uses Virtual DOM which is like a lightweight copy of the actual DOM (a virtual representation of the DOM). So for every object that exists in the original DOM, there is an object for that in React Virtual DOM. It is exactly the same, but it does not have the power to directly change the layout of the document. Manipulating DOM is slow, but manipulating Virtual DOM is fast as nothing gets drawn on the screen. So each time there is a change in the state of our application, the virtual DOM gets updated first instead of the real DOM.
What does lifting state up mean and why do we do it?
In React, sharing state is accomplished by moving it up to the closest common ancestor of the components that need it. This is called “lifting state up”.
Why do we set a key property when we map over an array in React?
Keys help React identify which items have changed, are added, or are removed. Keys should be given to the elements inside the array to give the elements a stable identity.
React uses the key prop to understand the component-to-DOM Element relation, which is then used for the reconciliation process.
Unique keys allow React not mix up the elements and avoid to mutate incorrect elements.
What are the core principles of Redux?
Single source of truth The global state of your application is stored in an object tree within a single store.
State is read-only The only way to change the state is to emit an action, an object describing what happened.
Changes are made with pure functions
How do I make an AJAX request using Redux?
In old redux we apply redux-thunk middleware which allows you to define async actions.
What are the benefits of using Redux DevTools?
Redux DevTool allows us to dispatch actions without writing any code. We can add our actions in dispatcher and it works just like action dispatched via Redux API. This kind of mocking helps in testing side effects and dependent actions.
How do I use React DevTools? What does this help me with?
It enables developers to debug their code inside their Developer Tools.
We can check the props/ state/ hooks of the component
We can edit the props/ state from dev tools
We can search for a component
We can check the component’s tree
We can log a component’s data in the console
Closure
Closures are inner functions that have access to the outer function’s variables and parameters. Even after the outer function’s execution is finished, the inner functions have access to the variables in the outer function.
What is redux-thunk?
“thunks” are a pattern of writing functions with logic inside that can interact with a Redux store’s dispatch and getState methods. Using thunks requires the redux-thunk middleware to be added to the Redux store as part of its configuration.
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
React context vs Redux
The main difference between these two libraries is that Redux deals with changes of the state in a centralized manner. On the other hand, Context deals with them as they happen on the component level.
What’s the benefit of using async/await?
Code is easily readable
Use numerous async functions in a row
Simpler debugging process
More convenient way of error handling
What is cookie?
Cookies vs localStorage vs sessionStorage?
Cookies - the simplest form of browser storage.
Key-Value pairs.
Often set by the server - logging info.
Can also be created via document.cookie.
Local storage - part of the web storage API.
System for storing information in the browser.
No expiration date.
Session storage - the same.
Expires at. the end of a session.
What is prototypal inheritance?
All javascript objects inherit properties from a prototype.
For example,
Array objects inherit properties from the Array prototype.
On top of the chain is Object.prototype. Every prototype inherits properties and methods from the Object.prototype.
A prototype is a blueprint of an object. The prototype allows us to use properties and methods on an object even if the properties and methods do not exist on the current object.
What is the DOM?
DOM stands for Document Object Model.
DOM is a programming interface for HTML and XML documents.
When the browser tries to render an HTML document, it creates an object based on the HTML document called DOM.
Using this DOM, we can manipulate or change various elements inside the HTML document.
How to compare two objects?
Objects are reference types so you can’t just use === or == to compare 2 objects. One quick way to compare if 2 objects have the same key value, is using JSON.stringify. Another way is using Lodash isEqual function 👏
What is asynchronous programming and why is it important in JavaScript?
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
What is hoisting?
Hoisting is the default behavior of javascript where all variables with var keyword and function declarations are moved on top of the scope. The scope can be both local and global.
What is apply, call and bind?
call()
It’s a predefined method in javascript
allows an object to use the method of another object.
accepts arguments
apply()
is similar to the call() method. The only difference is that, call() method takes arguments separately whereas, apply() method takes arguments as an array
bind()
returns a new function, where the value of “this” keyword will be bound to the owner object, which is provided as a parameter
What’s the difference between a variable that is: null, undefined or undeclared? How would you go about checking for any of these states?
null is actual value
undefined - when a variable in declared but not initialized.
use the typeof operator
what is higher order function?
What is a Higher Order Function? A higher order function is a function that takes one or more functions as arguments, or returns a function as its result. There are several different types of higher order functions like map and reduce.
What is the difference between == and ===?
Both are comparison operators. The difference between both the operators is that “==” is used to compare values whereas, “ === “ is used to compare both values and types
What is the difference between store and reducer
Store - Is what holds all the data your application uses. Reducer - is what manipulates that data when it recieves an action. Action - is what tells reducer to manipulate the store data, it carries the name and (not required) some data.
How do you send data up from child to parent component
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 .
How browser works
- When you visit a website, the web browser that you are using will contact the DNS server that will translate the human readable website name into a numeric IP address. Every website name is basically an alias for an IP address. So, DNS converts that URL into IP address, and each website has its own unique IP address.
Once a DNS server finds the IP address of the website, that IP address will be returned to the browser. - The browser will use the IP address to communicate with the web server.
- Now that your browser has a connection with the website’s web server, your browser will retrieve the html code of the specific page that is requested.
- Once your browser receives the HTML code from the web server, it will display that HTML code to you in the browser window.
- If and when you close that particular browser window, the connection with the web server will end.
How does HTTP work?
HTTP stands for Hypertext Transfer Protocol. It is a set of rules which is used for transferring the files like, audio, video, mage, text and other files. HTTP is a protocol that is used to transfer the hypertext from the client end to the server end, but HTTP does not have any security. Whenever a user opens their Web Browser, that means the user indirectly uses HTTP.
HTTP Requests are messages which are sent by the client or user to initiate an action on the server.
It has Request Header Fields: The request-header fields are used to allow the client to pass additional information to the server like the request and the client itself. The request header fields act as request modifiers, with semantics equivalent to the parameters on a programming language method invocation.
It has methods: get, post, patch, delete
The Server issues an HTTP Status Code in response to a request of the client made to the server. Status code is a 3-digit integer. The first digit of status code is used to specify one of five standard classes of responses. The last two digits of status code do not have any categorization role.
URI stands for uniform resource identifier. URIs define the identity of anything, including information resources such as web pages available on the internet and distinguish one resource from another.
Virtual DOM
a concept used in react to provide faster updates on the DOM, React keeps in memory a copy of DOM, whenever there is an update React updates virtual DOM and sync it with real DOM
State
JS variable, whenever its value is updated it triggers a rerender the application and a new value is displayed in the UI