UPDATE: At first, I believed that the following syntax was not functioning due to a mistake in my code and the fact that I have not encountered it being utilized in Javascript before. My primary concern lies in why this particular syntax is not more prevalent.
In C++, I often see strings looped through like this:
char s[] = "char";
for(int i = 0; s[i]; ++i) {
printf("it is a %c\n", s[i]);
}
So why isn't the same syntax — just defining the string as s = 'string';
— commonly used in Javascript?
For example:
s = "char";
for(var i = 0; s[i]; i++){
console.log("it is a " + s[i]);
}
Is this simply a matter of convention?