1. Write about something you learned this week.

This week we learned about APIs and Fetch APIs.

We use APIs for manipulating documents loaded into the browser. The most obvious example is the DOM (Document Object Model) API, which allows you to manipulate HTML and CSS — creating, removing and changing HTML, dynamically applying new styles to your page, etc. Every time you see a popup window appear on a page or some new content displayed, for example, that’s the DOM in action. Find out more about these types of API in Manipulating documents.

The fetch API provides a JavaScript interface for accessing and manipulating parts of the HTTP pipeline, such as requests and responses. It also provides a global fetch() method that provides an easy, logical way to fetch resources asynchronously across the network.

2. Why would you use something like the load event? Does this event have disadvantages? Do you know any alternatives, and why would you use those?

DOMContentLoaded — the whole document (HTML) has been loaded. load — the whole document and its resources (e.g. images, iframes, scripts) have been loaded. Read more on MDN.

The load event fires at the end of the document loading process. At this point, all of the objects in the document are in the DOM, and all the images, scripts, links and sub-frames have finished loading. To execute anything post document load, we fire these events. ‘DOMContentLoaded’ or jQuery’s loaded are another options. Read detailed discussion here and here.

3. What are the advantages and disadvantages of using Ajax?

Pros:

Improved User Experience-allows webpages to update serially by exchanging a small amount of data with the server.

Enhanced User Productivity-The AJAX library provides object-oriented helper functions that dramatically increase the productivity while decreasing frustration.

Reduced Bandwidth Usage and Increased speed-AJAX uses client-side scripting to communicate with the web server and exchange data using JavaScript.

Increased Compatibility-AJAX can be compatible with ASP.NET, J2EE, PHP, or any languages. It almost supports all popular browsers such as Internet Explorer 5 and above, Mozilla Firefox 1.0 and above, Apple Safari 1.2 and above, Opera 7.6 and above, and RockMelt.

Cons:

Browser Incompatibility-AJAX highly depends on JavaScript which is implemented differently for various browsers.

Insecurity-The webpage can be difficult to debug, increases the code size of your webpage, and makes your webpage prone to severe security threats.

Increased load on Web Server-The load can be increased depending on the user if you are adding an auto-update type that hits the server every few seconds.

4. Explain how JSONP works (and how it’s not really Ajax).

JSONP(as in “JSON with Padding”) is a method commonly used to bypass the cross-domain policies in web browsers (you are not allowed to make AJAX requests to a webpage perceived to be on a different server by the browser). JSON and JSONP behave differently on both the client and the server. JSONP requests are not dispatched using the XMLHTTPRequest, instead a <script> tag is created, whose source is set to the target URL. This script tag is then added to the DOM (normally the <head>). Read this, this and this for detailed answer.

5. Explain Ajax in as much detail as possible.

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)
  • JavaScript and HTML DOM (to display or use the data)

AJAX allows web pages to be updated asynchronously by exchanging data with a web server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page.

6. What does it mean when we talk about time complexity of an algorithm?

Let’s say time complexity of an algorithm for 𝑛n inputs is 𝑂(𝑛2)O(n2). That means the algorithm needs to execute totally (𝑛2)(n2) instruction from the beginning of the program till the end.

If 𝑂(𝑛2)O(n2) is a measure of instructions then why are we even calling that as time complexity?

Ok, let’s observe a scenario. Let’s say you have written an algorithm which has time complexity of 𝑂(𝑛2)O(n2) and you implemented it in a computer program. Now you are running that program on a computer which can execute 1 million instructions per second. Let’s say you have given 1000 inputs to that program. So it has to perform (10002)(10002) instructions which is nothing but 1 million instructions. As your computer can run 1 million instructions per second this program will be executed in one second.

7. What are the three laws of algorithm recursion?

  • A recursive algorithm must have a base case.
  • A recursive algorithm must change its state and move toward the base case.
  • A recursive algorithm must call itself, recursively.

Let’s look at each one of these laws in more detail and see how it was used in the listsum algorithm. First, a base case is the condition that allows the algorithm to stop recursing. A base case is typically a problem that is small enough to solve directly. In the listsum algorithm the base case is a list of length 1.

To obey the second law, we must arrange for a change of state that moves the algorithm toward the base case. A change of state means that some data that the algorithm is using is modified. Usually the data that represents our problem gets smaller in some way. In the listsum algorithm our primary data structure is a list, so we must focus our state-changing efforts on the list. Since the base case is a list of length 1, a natural progression toward the base case is to shorten the list. This is exactly what happens on line 5 when we call listsum with a shorter list.

8. How do you see yourself growing as a web developer?

I can see myself growing in so many ways. Eventually I want to continue to work with my current company and start working with software development team. We want to support new clients to built custom software. I’m excited learn more coding languages with the company. I can’t wait to work with a collaborative team and they can take me under their wing.