Kimberly Douglas
3 min readNov 15, 2020

--

F is for Function?

It has been a while since my last post, two (2) months to be exact, and while I haven’t been tracking my journey via this blog(or anywhere else for that matter), I’m happy to report that I have continued, albeit rather SLOWLY. I also got sidetracked and jumped down the rabbit holes that are CSS and HTML, which were a lot deeper than I expected. But now that I’m back on track, I think it’s only right that a recap of the completed topics is done.

We’ll start off with Functions, which is basically a chunk of code encapsulated in a binding. I learned that there are different ways to create a function:

  • The most common is similar to the declaration of a variable.
  • Declaration Notation

With this method, the function won’t follow the usual top to bottom flow of control and as such the function can be called before it is defined and your code will still run.

  • Arrow Functions

Which is basically saying if you put this in, the parameters, you’ll elicit this response, the executable statement.

An important feature of a function that was highlighted was the Optional Argument. With this feature, functions can be created with arguments that are optional. A default value can also be given to an argument in the event that the user doesn’t provide one.

If a value for “b” is not provided, the default value assigned to “b” will be used to execute the code in the body of the function.

The chapter also looked at scopes, differentiating between local & global scopes and how they affect your code. From what I understand, the local is confined to the function or block of code in which it resides while the global scope can be seen anywhere (meaning within the functions or blocks it is not apart of).

And now for my least favourite part of functions, recursion. A recursive function is one that calls itself repeatedly until a result is achieved (the stipulated stopping point is reached). Grasping this particular concept took me a while and the best explanation I could find for this was this video: https://youtu.be/LteNqj4DFD8.

This chapter basically highlighted how useful functions are by allowing one to eliminate repetition and organize your program into different sections based on their, well….function.

--

--