Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Why does the following code not work? Can't figure it out.
var string = ""; for (var x; x < numbersArray.length; x++) string += numbersArray[x]; alert(string);
string is empty at the end.
string
numbersArray.join("")
x is undefined, which is not less than any number. Therefore, your terminating condition is always false.
x
undefined
You probably want to start at 0.
0
Add a comment
var string = ""; for (var x=0; x < numbersArray.length; x++) string += numbersArray[x]; console.log(string);
Just make sure to initialize your x.
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
string" is considered bad practice. Btw. you could also usenumbersArray.join("").