0

Especially when dealing with DOM objects in JavaScript, there are often duplicates of one and the same string.

Should such a string saved in a global variable (or constant) or is JavaScript optimising by itself?

2
  • Strings are immutable, so you can't tell. Commented Jan 4, 2018 at 14:06
  • DOM objects are host objects anyway so we cannot tell how they are implemented. I doubt there's a lot of duplication in the data model. Commented Jan 4, 2018 at 14:14

1 Answer 1

1

Most likely there is an intern pool that gets used, but this is completely implementation dependent since the ECMAScript spec. doesn't tell vendors how to implement the functionality.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.