Scope can be very confusing when you're just starting out, especially with variable declarations!! So, I think that it's an important concept to know early on!😆
In this thread, we'll review scopes & its weird parts😉
A thread 🧵
1⃣WTF is scope?
Scope: visibility of the variable
Basically, scope refers to how your program can see or access a variable. Normally, when you declare a variable, It has global scope, meaning that it's accessible anywhere on your code.
2⃣ Variable global scope
Variables with global scope are declared OUTSIDE a function or a loop. If a variable's scope is global, it can be accessed anywhere in the code, even inside other functions or loops.
3⃣Variable local scope
On the other hand, a local scope variable is created INSIDE a function or loop. They cannot be seen nor used outside of that function/loop.
TDLR; you can only use that variable inside that function/loop.
4⃣Function global scope
Functions also have scope, not only variables. But, it's the same concept as a variable.
Normally, functions have global scope, so they're accessible anywhere in the code.
5⃣Function local scope
Functions have local scope too. When you nest a function, the child function is only seen within the parent function. The child function cannot be seen outside the parent.
6⃣Variable block scope
Another kind of scope is the block scope, which was introduced by ES6.
Generally, anything inside curly {} brackets is a block. It only works with keywords `let` and `const`, but not `var`.
Variables declared inside {} can only be seen inside that block
7⃣`var`
Block scope doesn't work with `var`. Variables declared with `var` are either function scope or global scope, but they're visible through blocks.
In other words, `var` acts like let/const inside a function, but it's global scoped with loops/conditionals/blocks.
8⃣`var` nested loop/function scope
Another thing you should know is that declaring a variable with `var` inside a child loop that's nested inside a parent function will be accessible to the whole function, but not outside that function.
The above is possible because of scope with `var`.
Remember that `var` behaves like global scope with if...else/loops/blocks, but it does have function scope.
On the other hand, remember that `let` does have if...else/loop/block/function scope, so if you declare the above with `let` instead, it'll be only accessible inside that loop
FINALLY we finished this thread!! It was quite long, but thank you for making it this far!!
I had trouble understanding scope when I first started, so I hope this helps y'all too😆
Follow me @codingyuri for more threads about difficult bullshit!! 😆
• • •
Missing some Tweet in this thread? You can try to
force a refresh
Loops execute a block of code inside them depending on a condition. If the condition is true, the block of code will execute. If the condition is false, the code won't execute, & it'll exit the loop
There are 3 kinds of loops: the while loop, the do while loop, and the for loop
I’ve seen people sell Web3/blockchain courses at a ridiculous price💀
so here are some FREE & GOOD resources to learn web3👇
don’t let your FOMO spend thousands on a course when there’s so many excellent free alternatives
the Web3 space is still so new that there isn’t guarantee of anything yet...it isn’t realistic to be job ready after a 3 week course that cost you thousands😅
Explained from the very start (for the real fucking beginners) 😆
A thread 🧵
With Web3 trending, there's a lot of people trying to get into the crypto and blockchain space.
There's plenty of resources for 'beginners', but as a person with NO technical background at all, most of it seems like technical jargon...what if you don't know any of that shit?😂
Friendly reminder that I'm still learning!
Feel free to correct me if I'm wrong and give me any advice, be nice though lol😂
Also, I'm hosting Web3 and blockchain conversations/threads on the Ponder app, so join me if you're interested!!
How improving your writing skills helps advancing your tech career
A thread 🧵
Writing isn't really a skill that aspiring devs think that'll help their careers.
Most of us spend all of our time learning new languages and frameworks, but improving your writing skills advances your tech career and helps you standout in the tech industry as well!
In this thread, we'll mostly talk about the benefits of technical writing, & a few tips on how to become a better writer.
Benefits ✅
-Writing === Learning
-Networking
-Problem solving
-Team communication
-User empathy
-New career opportunities