What is API, arguments, and parameters?


What is an API?

API stands for Application Programming Interface. The actual term API can mean a wide variety of things although you typically hear about in a specific sense in the context of internet apps. For example, you might hear that Facebook has an API for external software developers. What this means is that any developer can interact with Facebook’s platform using a standard determined by Facebook.

To give you an illustrative example of what API is, let’s use an example of a sushi restaurant. Below, I’ve created a function called ‘sushiRestaurant’ that has three named parameters.

var sushiRestaurant = function(soup,sushi,dessert){  
  // Other code inside
}; 

So let’s say I’m a customer and I visit this sushiRestaurant and give an order. You could write an order in Javascript as:

sushiRestaurant(‘miso soup’,’spicy tuna roll’,’green tea ice cream’);  

This order (i.e. function invocation) passes in three arguments that specifies what type of soup, sushi, and dessert I would like to have.

If I invoked sushiRestaurant and only passed in two arguments (‘miso soup’,’spicy tuna roll’)the sushi restaurant would by default assume that I don’t want a dessert. But what if I pass in four arguments? The sushi restaurant was only expecting three arguments. The fourth argument would normally be ignored.*

*The exception is if the function handled arguments in excess of its parameters by accessing the arguments object

Summary

  • APIs provide a way of interacting with a particular module / program
  • Parameters are stated in the function definition (whether it is function declaration or function expression)
  • Arguments are passed in when invoking, calling, or applying a function.