Functions & Scope

Guidelines

via GIPHY

  • The more you participate the more you learn!
  • Use Zoom’s Raise Hand feature
  • Protect the Zoom chat!
  • 🤯 The moment you are confused, raise your hand. You’re not alone!
  • “I don’t know” is OK. Guessing is also OK! Mistakes => Learning!
  • 📷 on 🙏

Coding Along (not required!)

via GIPHY

  • it can help
  • it can also hurt 😬
  • If you get stuck, take a screenshot and refocus on our discussion
  • 💡Everything is recorded!
  • Focus on high level understanding > implementation
  • Comfort solving errors and fixing bugs will come with practice and experience

My Setup

VSCode extensions:
Extension Description
Draw.io Integation for making diagrams from within VSCode
Live Server for opening a webpage in the browser that will reload when the code is saved
vscode-reveal for opening the slide.md files in the browser to display slideshows
Tabnine AI Autocomplete for code completion suggestions based on context

Lecture Goals

  • Describe what functions are
  • Regular functions vs arrow functions syntax
  • Explain the difference between:
    • Block scope
    • Function scope
    • Global scope
  • Understand functions as first-class objects
  • Identify higher-order functions
  • Define callback functions and higher-order functions

Functions

functions

() => {} vs function() {}

regular to arrow function conversion

  • syntax
  • simplified vs fully featured
  • interchangeable for now (hoisting! 😅)
  • read more about differences (or feel free to bookmark for later)

arrow function to reegular function conversion

Scope & The Scope Chain

Scope and the Scope Chain

Awesome Blog post on Scope and the Scope Chain

Visualizing Scope

Scope Castle Visual Metaphor

Callbacks and HOF

Callbacks pt1

Higher Order Functions

  • accept a function as a parameter
  • (and/or) return a function

Let’s Code!

Function Parameters Behavior
helloWorld none returns “Hello, world!”
formatPrice price (float) returns the price like so: “$2.99”
blurb book (obj) returns a string representation of the book with title author and price

Callbacks and Iteration

Callbacks pt2

Links!

Resource Location Description
Starter Code GitHub Repo separate folder for each day’s lecture contains the code and any related assets
Recordings Google Sheet Links to the starter & solution code for each days video along with the video link and a notetaking doc you can use for practice

Resources