Not even a full week into working on my project, I was in the thick of it. I started to doubt myself. One of the project requirements were to implement three AJAX calls. I implemented six; three create, two retrieve, and one update action. Talk about tedious, and time consuming!!! Making six AJAX calls with the frontend, I understand how to use fetch better to send and retrieve data from the backend. With the amount of time I had to complete this, and all of the bugs I ran into, I wasn’t able to include error handling, and a few other things which are necessary for an ecommerce platform. With that said, I am not disappointed in the progress I made over the course of these past 3 weeks.
Hoisting & Scope
Hoisting and scope work in conjunction with one another to execute functions and process information being passed to them throughout scripts. They also determine where variables can be accessed.
Hoisting allows us to access variables, and functions before they are executed. With ES6 included function expressions, which are NOT hoisted. If a function expression is called before it is declared, code will break and you will receive a reference error.
const which have a local scope or block scope. They cannot be accessed before declaration, while
var can. Using
var and anything with a global scope can cause naming collisions so it is necessary to use caution with those.
Using this static class method as an example, we see there’s a constant called
cart . Since
const cart is defined within a function, it has a local scope. Also, since it is declared with
const and not
var it has a block scope, and is not hoisted.
cart cannot be accessed outside of this function, and if it is tried, a reference error would be thrown.