Constants
Constants were introduced in ES6(2015), and use a const keyword. Variables that are declared with const cannot be reassigned or redeclared.
Example:
const VERSION = "1.2";
📝 Task:
[ ] Run the program mentioned below and fix the error that you see in the console. Make sure that the code result is
0.9when it is fixed in the console.const VERSION = "0.7"; VERSION = "0.9"; console.log(VERSION);[ ] Write a program that prompts user to enter a temperature in degrees Celsius, then use constant
CONVERSION_FACTORwhich equals to9/5to convert to degrees Fahrenheit.const CONVERSION_FACTOR = 9 / 5; /* Start your code from here*/
💡 Hints:
- Visit the Variables chapter for more info about const and also look for "TypeError assignment to constant variable" in search engines to learn a fix.