My first SPA!

Posted by Kyle Stough on November 23, 2020

After passing my Ruby on Rails project review I was beyond excited to begin learning Javascript so I could finally build my very first SPA! I have learned that most websites incorporate some form of a single page application and learning how to build a fully functioning SPA on my own will take my skillset to the next level. I look back at learning Ruby for the first time and how foreign all of the concepts and forms were to me, however, now that I understand the fundamental concepts of the coding world, learning Javascript was just that much easier when it came to learning the basics.

The most challenging part about building this application was understanding how scope operates and is utilized in Javascript. Understanding scope has saved me hours upon hours of debugging and offers potentially quick solutions when you are sure your code’s syntax is correct. In JS, the variable declarations ‘let’ and ‘const’ support block scoping, however ‘var’ does not. Therefore, if I had declared a function that set two variable declarations for the same term, the first at the top of my function before my block statement, and the second within the block statement itself, calling on the variable set solely relys on what declaration term was used, where it was declared, and where it is being called upon for return. If I were to call upon the set variable using ‘const’ or ‘let’, these terms will check for the logic declared inside of my block statement. However, If I were to call upon the variable that used ‘var’, we would not see it check for the logic inside of our block statement for this function and it would return the value declared outside of our block statement. Lastly, should we need to declare a variable without any of these 3 terms, ‘let, ‘const’,or ‘var’, that variable will become a global variable that is accessible anywhere in the file.

The most rewarding piece of building this application was understanding the flow of a single page application that incorporates much of the Ruby on Rails material we have been learning the past couple of months. Once I was able to understand how a Rails API backend is able to communicate with a modular JS frontend, the user experience and flow of the application seemed like something I would want to incorporate in the websites and applications I build moving forward. From what I’ve collected, I understand that our rails API backened creates a database and potentially offers the user CRUD funtctionality in order for them to edit said database, as long as the functionality to do so is also provided to them through our JS frontend. Our JS frontend will be accessible to our backend through our AJAX fetch requests. A fetch request first retrieves data from our API backend, next it uses the ‘.then()’ method to catch the response sent by our request, and afterward, another .then() method to translate our captured data into json(user friendly) format.

With 4 out of 5 projects down, I have never been more excited to reach my goal and graduate from Flatiron. I know there is still work to be done and understand the work will never stop, but I am ok with that as long as I get to spend my time doing what interests me. I have found a great community of people to work with and can’t thank my cohort and instructor enough for assisting me through my journey into the Software Engineering world.