DEV Community

Cover image for       To Curly Brace is to Block
Salah Uddin
Salah Uddin

Posted on

To Curly Brace is to Block

I've wrestled with making this blog post(let alone my first one!).

I'll be briefly discussing global and block scopes, with more an emphasis on the block scope. Why did I wrestle(a match I clearly lost) with this? To me, seemingly to others but not myself, block scoping was a very basic component of JavaScript.

Look, I've visited global and block scopes before, in fact in a boot camp I left I was taught it. Do not ask me why but I did not understand it when it was taught. It may be I'm not good at soaking in ideas as I listen to them but rather need to be able to implement them at my speed. To that end, Codecademy has been a huge boost.

Here's a bit of code, the global scope is everything outside curly braces. Literally everything in the curly brackets is block scope.

Think of it this way, "const twitter = '@mynameissalah'" is an h1 tag & everything in curly brackets is the css for the h1. That is to say, the curly brackets much like the css both respectively add a functionality to the parent they are assigned to.

I hope this helps at least one person! I feel like I was the outlier who didn't understand this easily while others seemed to—until it clicked & it was wildly simple. I don't learn as easily as most people & if that's you as well, hi! Wishing you the best in your learning, be easy on yourself. :]

*if I've made any mistakes or made things potentially confusing PLEASE contact me to correct me. I am by no means a teacher, I'm still learning so please let me know!

Top comments (4)

Collapse
 
waynejwerner profile image
Wayne Werner

This is actually why a lot of bugs happen:

if (foo)
    do_thing();
    do_something_else();
Enter fullscreen mode Exit fullscreen mode

That will burn you down because what you think is:

{ do_thing(); do_something_else; }
Enter fullscreen mode Exit fullscreen mode

But it's closer to

{ do_thing(); }
{ do_something_else(); }
Enter fullscreen mode Exit fullscreen mode

That's not entirely correct, but it can be helpful to think about it that way.

Collapse
 
kritishd8 profile image
Obscure.

I didn't know spotify had a banner that could play on any website. I like it lol.

Collapse
 
salah profile image
Salah Uddin

Yeah I was surprised seeing it, hadn’t before reading blog posts on here—figured might be a cool little thing to add. Probably going to do this for my future ones too!:p

Collapse
 
kritishd8 profile image
Obscure.

Great! It looks like a really good idea , The reader can choose to play the song recomended by the writer while reading. I will try to follow this idea too when i start writing blog posts.