JavaScript concatenate string and variable | Simple example code

To make a string out of a string and a passed variable in JS use concatenation to combine the variable to another string.

Simply just add a plus sign+ between the strings or string variables you want to connect.

JavaScript concatenate string and variable Example

HTML example code:-

String and String variable or String and integer variable both are concatenated same way in JavaScript.

Note: You can use a single quote or a double quote it doesn’t matter as long as your opening and closing quotes are the same.

Output:

JavaScript concatenate string and variable example

Do comment if you have any doubts and suggestion on this Variable and string topic of JS.

Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.