Question

I am currently learning a little bit of JavaScript and had a question.

In PHP, I am used to binding text and strings together with a simple dot like this:

echo "Text" . $String . "anotherText" . $anotherString

Is this possible in JavaScript? (Not the echo, but the binding of the strings and text.)

Was it helpful?

Solution 2

In JavaScript it's + instead of .

Example 1:

document.write("Text" + somestring + "anotherText" + anotherString);

Example 2:

alert("Text" + somestring + "anotherText" + anotherString);

Example 3:

var john = "Text" + somestring + "anotherText" + anotherString;

OTHER TIPS

The + is the concatenation operator in JavaScript:

"Text" + somestring + "anotherText" + anotherString;

Yes just, add:

'Text' + str + 'anotherText' + anotherString;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top