Javascript x Rails: Drinks

Capsule Coding
2 min readJan 19, 2021

For my javascript project i chose to go with a simple drink maker app that allows you to show your bartending skills and share your mixes. When it comes down to the difficulty of this project I would rate this project at a 8 for me only because this is my first time coding in general. Javascript was a tough time for me, coming from a guy who has never coded a day in his life. Javascript is completely different from Ruby and nothing was able to be carried over from the last mod. I had to completely understand Javascript from scratch and it was a hard time. I however liked to talk about the difference of var, let and const.

VAR

The main difference between var and let is instead of being function scoped, let is block scoped. Var is also function scoped and when trying to use a variable declared with var before the actual declaration, you’ll just get undefined. A scope method is the availability or use of a code in other areas of your code. Var declarations are globally scoped or function scoped. When a var is declared outside the function the scope is global. Which means it can be used anywhere in the code. When it is declared in a function, var is function scoped and can only be used within that function.

LET

Let is a signal that the variable can be reassigned, we see this happen in as a counter in a loop, or a value swap in an algorithm. It also signals that the variable only used in the block it’s defined in, which is not always the entire containing function. If you try to access a variable declared with let before it’s declared, instead of getting undefined (like with those variables declared with var), you’ll get a ReferenceError. Let is more suitable for variable declaration. It is the new improvement to var declarations. It also solves the problem with var.

CONST

Const is a signal that the identifier will not be reassigned. Once you’ve assigned a value to a variable using const, you can’t reassign it to a new value. You should always use const but if you know the variable is going to change try let. The reason for this is by using const, you’re signaling to your future self or others that have to read your code that this variable shouldn’t change.

Now that you have an understanding of Var, Const, and Let go out and apply it into your javascript code. Just remember the main differences and the reasons why you would use one over another.

--

--