Is there a way to use constants in JavaScript?
If not, what’s the common practice for specifying variables that are used as constants?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since ES2015, JavaScript has a notion of
const:This will work in pretty much all browsers except IE 8, 9 and 10. Some may also need strict mode enabled.
You can use
varwith conventions like ALL_CAPS to show that certain values should not be modified if you need to support older browsers or are working with legacy code: