Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
80
rated 0 times [  84] [ 4]  / answers: 1 / hits: 155310  / 13 Years ago, tue, april 26, 2011, 12:00:00

I want to declare string constants in JavaScript.



Is there is a way to do that?


More From » constants

 Answers
-24

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.


[#92568] Saturday, April 23, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
minab

Total Points: 701
Total Questions: 104
Total Answers: 91

Location: Saint Pierre and Miquelon
Member since Fri, Jan 28, 2022
2 Years ago
;