Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAaron Thomas
Full Stack JavaScript Techdegree Student 13,189 Pointswhy not use a "let" statement for the first and second sections? Then simply overwrite the code?
here is what I did...
// Collect input from a user
let userNum1 = prompt('Type a number. This will be your lowest.');
let userNum2 = prompt('Type a number. This will be your highest.');
// Convert the input to a number
userNum1 = parseInt(userNum1);
userNum2 = parseInt(userNum2);
The code runs just fine and works just like in the video. I want to know if this is actually bad practice or if this creates a problem I'm just not aware of at the moment. It seems to me unnecessary to store the "parseInt() " value into another variable when we can just overwrite the original variable.
1 Answer
Julie Branyan
Full Stack JavaScript Techdegree Graduate 16,337 PointsHi Aaron - The variable let
will work in this instance you showed above, however if you want to use the original inputLow or inputHigh variable in a different way, you've already reassigned it to a different value and can no longer use the input. const
prevents a value from being inadvertently reassigned and makes it clear how its being used in the code. This is beneficial in larger projects from preventing confusion on what the variable is assigned. I like the article below from medium that gives a little more detail.
https://medium.com/javascript-scene/javascript-es6-var-let-or-const-ba58b8dcde75
Aaron Thomas
Full Stack JavaScript Techdegree Student 13,189 PointsAaron Thomas
Full Stack JavaScript Techdegree Student 13,189 PointsThanks ! Yea I get it now. That article explained a lot. Better to use const as the default.