javascript - Does defining a frequently used string as a variable improve performance? -
this question has answer here:
in languages, used strings defined variables/constants, called instead of literal strings. same javascript? in particular, have frequent use of string 'none'
. instead of writing literal 'none'
everywhere in code, improve performance if define:
var none = 'none';
and use none
everywhere in code? or, there way intern literal string expression evaluated once?
literal strings automatically interned javascript compilers. var = 'hello'
, var b = 'hello'
pointing @ same copy of 'hello'
string in memory, no need further optimization on part.
the way make sure different string objects created same string value defining each 1 via string global object, i.e.:
var = new string('hello'); var b = new string('hello');
Comments
Post a Comment