Const vs let in Kelvin weather exercise

Hi everyone,

I am a newbie in coding and JS specifically. I have a question about Kelvin to Fahrenheit exercise, specifically the use of const and let variables:
https://www.codecademy.com/paths/front-end-engineer-career-path/tracks/fecp-javascript-syntax-part-i/modules/fecp-learn-javascript-syntax-introduction/projects/kelvin-weather-javascript

The correct variable for Kelvin and Celsius was const. While let for Fahrenheit. Could we not use let for all values?

If the end result was to change Kelvin to different values to see the conversion to Fahrenheit, could we not have kept re-assigning values to Kelvin by kelvin = 0; or kelvin=100; and then printing to console each time the value was reassigned?

The exercise asked for two different types of variables probably to practice using both let and const. But, you are right, using let for them all would also have worked as far as functionality goes. But in general it’s good practice to use const for values that are not supposed to change. As code gets more complex, this can help prevent accidentally changing variables that should stay constant.

4 Likes

Thanks for your prompt reply and clarification.