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.)

有帮助吗?

解决方案 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;

其他提示

The + is the concatenation operator in JavaScript:

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

Yes just, add:

'Text' + str + 'anotherText' + anotherString;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top