Many browsers' implementations (and Node) have constants, used with const.
const SOME_VALUE = "Your string";
This const
means that you can't reassign it to any other value.
Check the compatibility notes to see if your targeted browsers are supported.
Alternatively, you could also modify the first example, using defineProperty() or its friends and make the writable
property false
. This will mean the variable's contents can not be changed, like a constant.