Michael J. Stokes | Learning React ES6 : Understanding Const and Let Variables


Today’s React lesson was the understanding of using const and 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.



No Comments Yet

You can be the first to comment!


Leave a Comment






Previous Post : « | Next Post : »