In lots of languages like C, C++, Java, and so on char is a primitive information type however in JavaScript, there is no unique information type to save characters. Internally JavaScript shops characters as String just. In JavaScript, a String of length just is thought about a character. Because a character is likewise a string so character likewise gets saved in a string continuous swimming pool.
The string continuous swimming pool is a little cache that lives within the stack. JavaScript shops all the worths inside the string continuous swimming pool on direct allowance. The string continuous swimming pool exists primarily to decrease memory use and enhance the reuse of existing circumstances in memory.
Let us now comprehend with a fundamental example, how characters are saved in memory.
Example 1: In this example, we will save characters in variables.
Javascript
|
Output: Here, we can see that internally all the characters are being saved as String and strings with the very same worth describe the very same place in the memory to decrease memory use.
string . real . incorrect
Example 2: In this example, we will save characters with the very same worth however at various memory areas.
Javascript
|
Output: We can observe, that now the character is being saved as a things and each brand-new circumstances of a things is designated a brand-new place in the memory although it includes the very same worth.
object . incorrect . real
Conclusion:
When we are keeping characters utilizing simply quote(“) marks then variables having the very same worth are saved at very same place in the String Consistent Swimming Pool however if we utilize brand-new keyword then unique memory place is appointed to each worth even if they have the very same worth