Please do not hijack old threads. But as as answer to your problem, do not use + use '.' (dot). For example,
echo "<script>alert('text".$varName."')</script>"
//OR
echo "<script>alert('text {$varName} ')</script>"
If you have further doubts please start a new thread.