yuri 🇰🇷 Profile picture
Aug 2, 2021 12 tweets 4 min read Read on X
WTF is the deal with scope?😤

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
 

Keep Current with yuri 🇰🇷

yuri 🇰🇷 Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @codingyuri

Sep 11, 2022
fuck javascript loops and their scope, they're confusing AF➿

so i've made it easy for y'all !!

here's a quick mini-tutorial & some things to keep in mind while you're learning loops 👇
BTW, i wrote a more detailed article about loops, but read this twitter post for a quick read.

yurilee.hashnode.dev/fucking-javasc…
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
Read 12 tweets
Feb 8, 2022
CSS box model is fucking hard

here's a brief explanation for dummies like me:

A thread🧵

#100Devs 💪
WTF is CSS box model?

basically, just a term to talk about design and layout.

everything on a webpage is a fucking box.

the CSS box model is a box around every HTML element. it consists of the actual content, padding, border, and margin.
from the inside out, the order of the box property is content, padding, border, and margin.

on the image below:
- the actual content is highlighted in blue
- padding is light green
- border is highlighted the darkest color
- margin is orange
Read 13 tweets
Jan 2, 2022
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😅

Here are my favorites:
1. blockchain.berkeley.edu/courses/

Blockchain at Berkeley gives a great introduction to cryptocurrency and the blockchain.

IMO, it’s great for beginners who don’t know shit, as it helped me have a grasp of what the hell all of this is.

It really painted the whole picture for me!
Read 6 tweets
Dec 21, 2021
WTF is crypto and blockchain??

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!!

getponder.com
Read 24 tweets
Oct 14, 2021
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

Tips:
-Get to the point
-Clarity
Read 26 tweets
Oct 3, 2021
5 tips for web dev newbies
My advice.

A thread 🧵
1️⃣ ONLY COMPARE YOURSELF TO YESTERDAY'S YOU

As long as you learned something new today, you've made progress.

It can be a single word, concept, whatever small it may be, as long as you know something today you didn't know yesterday, you're making progress✨💘

👇
This is THE secret to a healthy mindset, don't be too hard on yourself. Learning something new in itself is already fucking hard!!!

Everyone takes their own time and has their own way of understanding things. Your journey is YOURS alone.
Read 10 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(