Top 5 Javascript Trending Interview Questions 2020

Question: what happens when you type in a URL in the browser?

Answer: “What happens when you type in a URL” is a deceptive question commonly asked in tech interviews. If you look online, there are many very detailed resources but few concise explanations of how a web browser, a server, and the general internet work together.

This is how I would explain it:

  1. You enter a URL into a web browser
  2. The browser looks up the IP address for the domain name via DNS
  3. The browser sends an HTTP request to the server
  4. The server sends back an HTTP response
  5. The browser begins rendering the HTML
  6. The browser sends requests for additional objects embedded in HTML (images, CSS, JavaScript) and repeats steps 3-5.
  7. Once the page is loaded, the browser sends further async requests as needed.

Question: What is the execution order of async defer and normal script ?

Answer: This image explains normal script tag, async and defer

enter image description here
  • Async scripts are executed as soon as the script is loaded, so it doesn’t guarantee the order of execution (a script you included at the end may execute before the first script file )
  • Defer scripts guarantees the order of execution in which they appear in the page.

Question: What are Higher Order Functions in Javascript?

Higher-order functions are functions that take other functions as arguments or return functions as their results.

Taking an other function as an argument is often referred as a callback function because it is called back by the higher-order function. This is a concept that Javascript uses a lot.

For example, the map function on arrays is a higher-order function. The map function takes a function as an argument.

Question: What is javascript code bundling?

Javascript bundling is a technique that groups separate files in order to reduce the number of HTTP requests that are required to load a page. Bundling is commonly used in today’s “module-based” development where some functionalities are basically split into Modules (roughly explained). For loading modules, we usually use some of popular module loaders such as rollup.js or RequireJS.

HTTP2 is here so this technique will be probably deprecated in the future. You could still use bundling for reducing the number of requests for a specific page but I don’t think it will be worth of it.

Question: Why we put CSS on top and javascript on bottom ?

  • Style declarations should be as close to the top as possible, since browsers won’t render your page before loading the CSS (to avoid a flash of unstyled content)
  • Script tags should be as close to the bottom as possible, since they block browsers from parsing after the tag before it is loaded and complete (because the script may change the document with document.write)

Leave a Reply

Your email address will not be published. Required fields are marked *