JavaScript Scope

JavaScript Scope

The further I get along in my project the greater my love and passion grows for web development.

Over the past few days. I have been busy working on my current project. So far it has been a blast! The more I learn the more I love web development. Though there have been a few hiccups of course due to user error. I learned a hard lesson in JavaScript scope. I was working on my email input validation. I was able to get the first block of my if statement to work. However, if the form failed validation with the RegExp, I was getting an error when it reached the 2nd block. I spent a good 4-5 hours trying to figure out the issue. Turns out it was the scope of the variable I created. Instead of making it available to the whole function. I declared it in the first block of my if statement. Once I figured that out there was pure joy. I decided to stop after that though. It was a little after 3 am and I was beginning to break more things than build or fix. The time flew by though since I was having so much fun. Here is a look at the code for my email validation.

Form Validation Code snippet
Form Validation Code snippet

Stop the endless cycle of tutorials and just build

Sometimes we can get so caught up in learning materials like self-paced tutorials, videos, books and on and on. We don’t actually begin to build anything. Then once we start to build a project and see a blank text editor it can be a bit intimidating as we don’t have a tutorial to hold our hand. The best way to get past this is when you learn something new implement it in a side project or something you want to build it can be small or big!

During the time I have been working on this travel website. I would need to look up how to start/complete certain features I wanted to implement and it has helped a lot. Because I am looking up specifically how to complete a certain feature in code and then instantly go and build it. Instead of watching someone code for a few hours and then try to remember how they approached certain problems, then try to remember how to recreate it on my own. Even if you are the best note taker. It can be difficult to recall how to do things that you need to once it is time to use it.

When I first started to learn about programming I remember reading a lot of post. They all had a common message. Build, build, build. I doubted it, I thought I needed to learn all the fundamentals of the language (which I still believe is a good decision) but also know about more advanced techniques before I should build. I have done countless tutorials, Codecademy, Team Tree House, FCC etc. I switched back and forth between them all. I felt like I wasn’t making any progress outside of having a strong foundation in the language. The moment it all clicked was when I actually started to build and go to the MDN to read about a property or method I needed to use.

Utilize the MDN and become more familiar with it

Seeing the MDN the first time on your own and trying to interpret it can also be intimidating. I use to read it when I was first learning about JS and it all looked like a foreign language to me. I now have it booked marked on my favorite pages for the main resources I use. I can read through the syntax and better implement what it is trying to get across to me at a much faster rate and it is only getting better.
In all, I strongly recommend after you feel comfortable with the basics of JS i.e., variables, syntax, functions, scope, etc then jump right in and just build something. It will be challenging to me that is the fun part! You may feel like you are constantly having to look up how a piece of code works, or how to accomplish what you are trying to code. There is nothing wrong with that, it is how we learn. Trial and error will always be a part of coding. Once we begin to embrace it, it can become much easier.

When you are first beginning to learn and you pick a project. Don’t aim too high or low. You want something challenging but still achievable at the same time. Pick something you are passionate about and just build. When you do, that it makes it easier when things get a bit tough. Your passion for it will help you get through. Read, research and repeat. Maybe it will take you a few days to figure out an error. That is ok too! Next time when you face the same problem. You will now exactly how to fix it and maybe even make it better. Growth comes with practice and experience. After a while, if you still aren’t able to figure it out. Don’t be afraid to ask for help.

Let’s all get out there and take a break from the tutorials and just build, instead of getting caught in the tutorial cycle.

There isn’t anything wrong with tutorials but after a certain point, we do need to break away and just start building products. That is when you really begin to learn, but most importantly retain what you are learning and continue to build upon that progress.

Code with friends and read others code

As developers, we spend a lot of time by ourselves learning and coding. It can be a bit mundane at times. Try to find a friend or meet new people in the community and do a bit of pair programming. It can be great to get fresh eyes on what you are working on from a different perspective. Building with other people that may be strong in different areas, that can help you both! There are many communities out there on the internet and people in the local community that may be in the same position as you. Networking can help go a long way. Until next time, happy coding my friends.


1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *