Like strings stored in javascript

I am looking for how strings are processed physically in Javascript. The best example I can think of is that in the Java api it describes storing strings as:

String str = "abc";" is equivalent to: "char data[] = {'a', 'b', 'c'};

I am told that it uses an array object and saves each character as its own object, which will be used / access later (usually I am wrong about these things!) ...

How does javascript work?

+7
source share
2 answers

Strings String objects in JavaScript. A String object can use the [] notation to get a character from a string ( "abc"[0] returns 'a' ). You can also use the String.prototype.charAt function to achieve the same result.

Side node: var a = 'abc' and var b = new String('abc') do not match. The first case is called a primitive string and is converted to a String object by a JavaScript parser. This leads to other data types, calling typeof(a) gives you String , but typeof(b) gives you an object .

+3
source

Strings are stored in the same format in javascript as in other languages. Suppose that var word = "test" than the word will be like an array of characters, and "t" will be at the 0th position, etc.

The last iteration accepting "word.length" will return undefined. In other languages, it returns as "\ 0".

0
source

All Articles