Something similar to this code returns a variable undefined error:

var firstVariable = "";
var secondVariable = "";
// later on...
secondVariable = firstVariable.length
alert("text text text " + secondVariable + " text text text.")

I need secondVariable to be globally defined and accept string pushes for other purposes, so changing that second line to

var secondVariable

doesn't seem to be a good option. But I'm not even sure whether the error is on line 2, line 4 or line 5. Can somebody help?

add semicolon to end of all statments for eg in line 4, 5

or post full code

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.