Property Access mistake?


#1

https://www.codecademy.com/courses/learn-javascript/lessons/arrays/exercises/property-access

So on Property Access it is explained that you can access each individual character in a string the same way you access things in an array.

And it gives the following example:

var hello = ‘Hello World’;
console.log(hello[6]);
// Output: W

‘W’ will be the output since it’s the character in the 6th position. This works because JavaScript internally stores strings in a similar way that it stores arrays.


Correct me if I’m wrong, but if you start counting from 0 then wouldn’t the character in the 6th position be ‘O’ not ‘W’?

Thank you for your time.


#2

I think you missed the space to count


#3

Space is treated as a character in JavaScript. So “W” is in the 6th position.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.