{"id":2380,"date":"2022-08-30T13:13:57","date_gmt":"2022-08-30T13:13:57","guid":{"rendered":"https:\/\/lvboard.infostore.in.ua\/?p=2380"},"modified":"2022-08-30T13:13:57","modified_gmt":"2022-08-30T13:13:57","slug":"10-entry-level-react-interview-questions-2","status":"publish","type":"post","link":"https:\/\/lvboard.infostore.in.ua\/?p=2380","title":{"rendered":"10 Entry Level React Interview Questions"},"content":{"rendered":"\n<p id=\"8b9a\">Interviews are the direct ways to land a job in more ways than you think. More ways than one you may ask? Yes! Interviews are not only for you to show your skills and what you know, but also a great way to see what you don\u2019t know, what people in the industry are asking for, and what you should focus on more.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p id=\"c982\">In this part, I\u2019ll be going over 5 React and 5 JavaScript questions.<\/p>\n\n\n\n<p id=\"3237\">In this article, I want to give you 10 questions and relatively short but comprehensive answers for entry-level developers, which I personally consider to be one of the most important ones. Again, these are just my opinions, so take them with a grain of salt.<\/p>\n\n\n\n<h2 id=\"0abd\">1. What is Virtual DOM and how does it work?<\/h2>\n\n\n\n<p id=\"b602\">By far, I get this question asked the most. I do have an article about how React works, where I talk about Virtual DOM in-depth&nbsp;<a rel=\"noreferrer noopener\" target=\"_blank\" href=\"https:\/\/javascript.plainenglish.io\/how-react-works-under-the-hood-277356c95e3d\">https:\/\/javascript.plainenglish.io\/how-react-works-under-the-hood-277356c95e3d<\/a>, but for the shorter answer, you can say this: virtual DOM is a virtual representation of the DOM, where updates are lightweight. The way it works is it compares its state to the virtual DOM snapshot that it took just before the update. Comparing the new and the old versions, React figures exactly which objects have changed and updates only those ones. This process is called diffing.<\/p>\n\n\n\n<p id=\"14da\">To sum up, here are the steps then happen in React when DOM gets updated:<\/p>\n\n\n\n<ol><li>It takes a snapshot of the current state.<\/li><li>The virtual DOM gets updated<\/li><li>It compares the current state to the snapshot taken before<\/li><li>React figures out which objects were changed<\/li><li>React changes&nbsp;<em>only that&nbsp;<\/em>objects<\/li><li>The real DOM now gets updated.<\/li><\/ol>\n\n\n\n<h2 id=\"32d0\">2. Name some of the most important lifecycle hooks and their purposes. (It\u2019s alternatives in new React Hooks)<\/h2>\n\n\n\n<p id=\"ac7e\">Let\u2019s rundown them in order. I\u2019ll make highlight the ones, that I think are most important and often used.<\/p>\n\n\n\n<p id=\"793b\"><strong>On render:<\/strong><\/p>\n\n\n\n<ol><li>constructor<\/li><li>static getDerivedStateFromProps \u2014<br>useEffect(() =&gt; {}, [props1, props2])<\/li><li>render<\/li><li><em>componentDidMount \u2014 useEffect(() =&gt; {}, [])<\/em><\/li><\/ol>\n\n\n\n<p id=\"60e1\"><strong>On re-render:<\/strong><\/p>\n\n\n\n<ol><li>static getDerivedStateFromProps \u2014<br>useEffect(() =&gt; {}, [props1, props2])<\/li><li>shouldComponentUpdate() \u2014 useMemo()<\/li><li>render<\/li><li>getSnapshotBeforeUpdate()- custom hook to hold previous state<\/li><li>componentDidUpdate \u2014 useEffect(() =&gt; {})<\/li><\/ol>\n\n\n\n<p id=\"8a0b\"><strong>Unmounting:<\/strong><\/p>\n\n\n\n<p id=\"ad52\">ComponentWillUnmount \u2014 useEffect(() =&gt; return {}, [])<\/p>\n\n\n\n<h2 id=\"746c\">3. Why do we use arrow functions in React and what problem do they solve?<\/h2>\n\n\n\n<p id=\"c485\">The&nbsp;<em>this&nbsp;<\/em>keyword works differently in arrow functions. They do not bind their own&nbsp;<em>this,&nbsp;<\/em>instead, they inherit one from the parent scope, which is called \u201clexical scoping\u201d. If we didn\u2019t use arrow functions, we would need to bind&nbsp;<em>this&nbsp;<\/em>to the parent, which is normally done in the constructor.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import React from 'react';<br>class MyComponent extends React.Component {<br>  constructor(props) {<br>    super(props)<br>    this.clickHandler = this.clickHandler.bind(this);<br>  }<br><br>  clickHandler() {<br>    console.log( this )<br>  }<br><br>  render() {<br>    return &lt;button onClick={this.clickHandler}&gt;Click Me&lt;\/button&gt;<br>  }<br>}import React from 'react';<br>class MyComponent extends React.Component {<br>  constructor(props) {<br>    super(props)<br>  }<br><br>  clickHandler = () =&gt; {<br>    console.log( this )<br>  }<br><br>  render() {<br>    return &lt;button onClick={this.clickHandler}&gt;Click Me&lt;\/button&gt;<br>  }<br>}<\/pre>\n\n\n\n<p id=\"f5b8\">The arrow function use is more readable and recommended.<\/p>\n\n\n\n<h2 id=\"51e3\">4. What are keys in React and why do we need them?<\/h2>\n\n\n\n<p id=\"d3b3\">In short, keys are used in React for diffing algorithm. With the help of keys React can tell which DOM node was changed and update only that one. They are essential when mapping over arrays .<br><code>&lt;ul&gt;<br>&lt;li&gt;New York&lt;\/li&gt;<br>&lt;li&gt;London&lt;\/li&gt;<br>&lt;\/ul&gt;<\/code><\/p>\n\n\n\n<p id=\"80d7\"><code>&lt;ul&gt;<br>&lt;li&gt;New York&lt;\/li&gt;<br>&lt;li&gt;London&lt;\/li&gt;<br>&lt;li&gt;Tbilisi&lt;\/li&gt;<br>&lt;\/ul&gt;<\/code><\/p>\n\n\n\n<p id=\"0ad7\">In this case, since we are inserting a new element at the end of the array, it will work well, because React just iterates over the list and generates a mutation whenever it finds a difference. Remember, React takes a snapshot before updating, so it looks at the previous list.<\/p>\n\n\n\n<p id=\"24b5\">But what happens if we insert a new element at the beginning of the array?<br><code>&lt;ul&gt;<br>&lt;li&gt;New York&lt;\/li&gt;<br>&lt;li&gt;London&lt;\/li&gt;<br>&lt;\/ul&gt;<\/code><\/p>\n\n\n\n<p id=\"7d95\"><code>&lt;ul&gt;<br>&lt;li&gt;Tbilisi&lt;\/li&gt;<br>&lt;li&gt;New York&lt;\/li&gt;<br>&lt;li&gt;London&lt;\/li&gt;<br>&lt;\/ul&gt;<\/code><\/p>\n\n\n\n<p id=\"30b2\">React will insert the city Tbilisi at the beginning, but it will also mutate every other element because it doesn\u2019t know they are the same.<\/p>\n\n\n\n<p id=\"d192\">That\u2019s where keys come to the rescue. With keys, React can match the original list to the new one, and only update just the necessary element.<br>This is why using unique IDs is always recommended for keys.<\/p>\n\n\n\n<h2 id=\"5488\">5.Why should you use React instead of real JavaScript frameworks, like for example Angular?<\/h2>\n\n\n\n<p id=\"7be4\">Unlike Angular or Vue, React is just a library, which of course has its pros and cons. To focus on the pros:<\/p>\n\n\n\n<p id=\"ef02\">React is more lightweight and allows the creation of dynamic applications. Also, since React is basically JS with some JSX, it\u2019s easier to get started with.<br>Using VDOM, makes web applications perform faster.<\/p>\n\n\n\n<p id=\"4133\">React uses a unidirectional data flow, which means that data flows from top to bottom. This makes debugging errors easier.<\/p>\n\n\n\n<p id=\"6dad\">There are many chrome extensions that make working and debugging React applications easier. Here are three of my favorites: Components, Redux and React Context. There are others, but these are the primary ones I use in almost every application.<\/p>\n\n\n\n<p id=\"bf69\">Since there is no React without JavaScript, you can definitely expect some JavaScript questions on the interview as well. Here are some of them.<\/p>\n\n\n\n<h2 id=\"2295\">6. What are the different data types in JavaScript?<\/h2>\n\n\n\n<p id=\"41a8\"><strong>Primitive data types:<\/strong><br>undefined \u2014 typeof \u201cundefined\u201d<br>Boolean \u2014 typeof \u201cboolean\u201d<br>Number \u2014 typeof \u201cnumber\u201d<br>String \u2014 typeof \u201cstring\u201d<br>BigIng \u2014 typeof \u201cbigint\u201d<br>Symbol \u2014 typeof \u201csymbol\u201d<br>null \u2014 typeof \u201cobject\u201d<\/p>\n\n\n\n<p id=\"8416\">There are also non-primitive data types that we should mention like Object, Array, Map, Set.<\/p>\n\n\n\n<h2 id=\"b357\">7. What\u2019s the difference between var and let?<\/h2>\n\n\n\n<p id=\"e2c4\"><code>var<\/code>&nbsp;is mostly used in before ES6 was introduced. Main difference between var and let is scoping rules. Variables declared by&nbsp;<code>var<\/code>&nbsp;keyword are scoped to the immediate function body (hence the function scope) while&nbsp;<code>let<\/code>&nbsp;variables are scoped to the immediate&nbsp;<em>enclosing<\/em>&nbsp;block denoted by&nbsp;<code>{ }<\/code>&nbsp;(hence the block scope.<\/p>\n\n\n\n<p id=\"c4a1\">The reason why&nbsp;<code>let<\/code>&nbsp;keyword was introduced to the language was function scope is confusing and was one of the main sources of bugs in JavaScript.<\/p>\n\n\n\n<h2 id=\"1543\">8. What\u2019s the difference between \u201c==\u201d and \u201c===\u201d?<\/h2>\n\n\n\n<p id=\"4ff8\">== compares just the value, where as === compares value and type as well.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/miro.medium.com\/max\/744\/1*QJaTG0pii7O80VADp19N8A.png\" alt=\"\"\/><\/figure>\n\n\n\n<h2 id=\"7ee3\">9. What\u2019s the difference between&nbsp;<strong>null<\/strong>&nbsp;and&nbsp;<strong>undefined<\/strong>?<\/h2>\n\n\n\n<p id=\"be43\">They both represent empty values, but the difference is that when you define a variable but do not assign anything to it, it becomes undefined automatically, but for null, you have to assign it. One other difference is that, as we discussed in our data types question, typeof undefined is undefined but typeof null is object.<\/p>\n\n\n\n<p id=\"3c46\">Going also back to our \u201c==\u201d and \u201c===\u201d answer, we definetly know that since null and undefined are different types, they do not strictly equal each other, but what may surprise you is that they loosely do.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/miro.medium.com\/max\/666\/1*EUuydR3Cuf9D6XyXh8Em_w.png\" alt=\"\"\/><\/figure>\n\n\n\n<h2 id=\"2917\">10. What is does asynchronous mean?<\/h2>\n\n\n\n<p id=\"a3b7\">Normally, a given program\u2019s code runs straight along, with only one thing happening at once. If a function relies on the result of another function, it has to wait for the other function to finish and return, and until that happens, the entire program is essentially stopped from the perspective of the user.<\/p>\n\n\n\n<p id=\"e453\">Asynchronous techniques are very useful, particularly in web programming. When a web app runs in a browser and it executes an intensive chunk of code without returning control to the browser, the browser can appear to be frozen. This is called&nbsp;<strong>blocking<\/strong>; the browser is blocked from continuing to handle user input and perform other tasks until the web app returns control of the processor.<\/p>\n\n\n\n<p id=\"cf40\">Asynchronous solves this problem by not waiting for other operations to complete. Imagine it like this: You are cooking pasta. You put water on the stove and are waiting for it to start boiling. That doesn\u2019t mean you shouldn\u2019t do anything until that, right? You can start preparing the seasoning, put up the plates, or anything else you might want to do. After the water starts boiling, you get back to it and put the pasta in it. That\u2019s pretty much how asynchronous functions work.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Interviews are the direct ways to land a job in more ways than you think. More ways than one you may ask? Yes! Interviews are not only for you to show your skills and what you know, but also a great way to see what you don\u2019t know, what people in the industry are asking &hellip; <a href=\"https:\/\/lvboard.infostore.in.ua\/?p=2380\" class=\"more-link\">\u041f\u0440\u043e\u0434\u043e\u0432\u0436\u0438\u0442\u0438 \u0447\u0438\u0442\u0430\u043d\u043d\u044f<span class=\"screen-reader-text\"> &#8220;10 Entry Level React Interview Questions&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[132],"tags":[],"_links":{"self":[{"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=\/wp\/v2\/posts\/2380"}],"collection":[{"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2380"}],"version-history":[{"count":1,"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=\/wp\/v2\/posts\/2380\/revisions"}],"predecessor-version":[{"id":2381,"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=\/wp\/v2\/posts\/2380\/revisions\/2381"}],"wp:attachment":[{"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lvboard.infostore.in.ua\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}