Today’s React lesson was the understanding of using
let variables. Unlike
var, let and const are block scoped. The main difference between let and const is that const variables has to be declared using an initializer or else it will throw an error. Let variables can be reassigned and prevents errors when trying to redeclare an already declared variable in the same scope which results in a more maintainable and readable code.
I learned in fact that you can create a react app by only declaring const variables if you plan on not doing any reassigning, which you would have to use declare variables using let.
Why var is hardly used in React? Declaring variables with var may or may not get to be reassigned and may not even be used for an entire function. Var was the strongest way to declare variables before ES6. Using const and let prevents bugs in an entire code.