Coding Log — February 11th, 2018 — Day 35
Coding Time: Full Day
Here’s what I did today:
Learned about Scope & Closures
I have a list of topics that I wanted to learn. It’s not really clear how they’re useful just yet.
I was anxious about reading an entire book on the topic (YDKJS). Can’t I just get the TL;DR? It seems like overkill when I’m still building really simple apps.
I decided to just read some articles and watch some YouTube videos for this. I hope it’s enough. It already feels too advanced for the code I’m writing right now, but I’m at least familiar with the concept now.
I have no specific recommendations for what the best articles/videos were. They were all either too basic or too advanced. If you want to learn about it, just read everything you can. I guess the best recommendation would’ve just been to read the book. But I just really didn’t want to.
On my specific journey through Scope & Closures these past 2 days, I also learned a bit more about some ways to respond to the DOM.
One example of this, something I want to try out asap,
querySelector is more static and
getElementsBy is more dynamic. It’s something to test.
I also realized I need to learn about callback functions. I don’t know what that word means at all.
But here’s what I did learn about scope & closures:
Scope is the area in which your variables are valid.
Variables defined inside of a function are only applicable within the function.
Variables defined outside of a function are still capable inside or outside of a function.
When there’s a function inside of a function, that’s called a closure. It has the scope of its parent function. The parent function does not have scope inside of the child function, except if a statement in the function is to return a variable.
This scope of the parent function does not apply when you call a child function instead of defining it within it.
I get it, I think? I don’t know. I can’t really think of much more to say than this. It just seems like, “Okay, cool. That happened.”
Be concious of run order and how variables can be misused and mutated into things that you didn’t think would happen. I mean, okay. I’ll organize my code a bit differently now. Cool?
Maybe start reading about AJAX/APIs? Maybe some about callback functions? Maybe some other stuff this theory-heavy internet deep dive leads me on?