Day 15: Advanced Functions & Scope

Brent Carey
2 min readJan 21, 2022

Intermediate Function Usage

In JavaScript, functions can be used just like other values. We can assign them to variables and pass them to other functions as arguments. We can pass a named function or an anonymous inline function. A typical function that takes a function as an argument is setTimeout, which is used to run a certain action after a set time period. Arrow Functions were also introduced in ES6 which give us a way to write cleaner (and cooler) looking code πŸ€“.

Arrow function example.

Scope

Scope refers to which variables are accessible in specific functions. Every variable has a scope that it can be used inside, outside of that scope we cannot use that variable. Variables that are declared inside of functions are local to that specific function. Variables declared outside of a function have global scope and can be accessed from anywhere. We should use const and let to declare our variables instead of var as they are block-scoped instead of function-scoped. Block scoped elements are local to functions, as well as loops and if-else statements.

Scope example

Closing

Finally back at it! Sorry for the long break between articles, I have been caught up in the holidays! Boot camp is back and I will be returning to my posts with all the content I have learned. I also secured my first job as a Front End Web Developer, so I am super excited to build something awesome for the client! ✌🏼

--

--

Brent Carey

Web Developer Studying at BrainStation πŸ§‘πŸ½β€πŸ’», documenting all the cool things I learn πŸ“š, anime inspiration too πŸ¦ΈπŸ½β€β™‚οΈπŸ¦ΉπŸ½β€β™‚οΈ.