Like this:

var str = 'blah blah blah';
str += ' blah';

str += ' ' + 'and some more blah';
Answer from karim79 on Stack Overflow
Top answer
1 of 5
87

Your code is correct. Perhaps your problem is that you are not passing an ID to the AddBorder function, or that an element with that ID does not exist. Or you might be running your function before the element in question is accessible through the browser's DOM.

Since ECMAScript 2015, you can also use template literals (aka template strings):

document.getElementById(`horseThumb_${id}`).className = "hand positionLeft";

To identify the first case or determine the cause of the second case, add these as the first lines inside the function:

alert('ID number: ' + id);
alert('Return value of gEBI: ' + document.getElementById('horseThumb_' + id));

That will open pop-up windows each time the function is called, with the value of id and the return value of document.getElementById. If you get undefined for the ID number pop-up, you are not passing an argument to the function. If the ID does not exist, you would get your (incorrect?) ID number in the first pop-up but get null in the second.

The third case would happen if your web page looks like this, trying to run AddBorder while the page is still loading:

<head>
<title>My Web Page</title>
<script>
    function AddBorder(id) {
        ...
    }
    AddBorder(42);    // Won't work; the page hasn't completely loaded yet!
</script>
</head>

To fix this, put all the code that uses AddBorder inside an onload event handler:

// Can only have one of these per page
window.onload = function() {
    ...
    AddBorder(42);
    ...
} 

// Or can have any number of these on a page
function doWhatever() {
   ...
   AddBorder(42);
   ...
}

if(window.addEventListener) window.addEventListener('load', doWhatever, false);
else window.attachEvent('onload', doWhatever);
2 of 5
40

In javascript the "+" operator is used to add numbers or to concatenate strings. if one of the operands is a string "+" concatenates, and if it is only numbers it adds them.

example:

1+2+3 == 6
"1"+2+3 == "123"
Discussions

javascript - Appending string to variable name - Stack Overflow
Is there a way to define variables in javascript to append them with another variable? var card_id; var card_links_grid+card_id; I'd like the second variable to be appended with the information fo... More on stackoverflow.com
🌐 stackoverflow.com
November 25, 2011
How to concatenate variables for this.state

I am trying to send over a variable from one component to another in a different js file

To be honest I'm not sure I follow what you're trying to do. If you're talking about string interpolation, there's a great thing in ES6 called Template Strings.

const clientID = `${vault.clientList}.${vaulNumber}`

Note: Those are Backticks, not single quotes!

More on reddit.com
🌐 r/reactjs
8
1
May 15, 2016
How can I add query string parameters to my URL?
Just add it in the url like this would be an option: Const zipcode = '280009'; Const city = 'old york' Axios.get(www.reddit.com/search?zipcode=${zipcode}&city=${city}) Obviously change the variables to whatever you want, this is an example. For more details we use the backtick quotes`` instead of regular ones when we want to pass in javascript values in strings. Then the variables get added into the url inside these ${}. I'm pretty sure you have your concepts wrong, pushing with router will navigate you to another component or page most of the times, if i'm correct you just want to send to an api and get a response? If so you should delete the history part. Edit: reddit formatting on mobile sucks, you need to add backticks around the url (``) More on reddit.com
🌐 r/reactjs
3
1
April 15, 2020
Check checkbox check state and append to array
Since you are using jQuery, it would be easiest to leverage its :checked selector , e.g.: $(".form-check input[type=checkbox]:checked") would return a jQuery collection containing all checked checkboxes inside .form-check element(s). Once you have that collection, you can use rest of jQuery methods, or convert it to Array and use plain JS or other library's methods, something like this example (note that you can inline getChecked function right into .click(), but I thought it was worth extracting it). More on reddit.com
🌐 r/learnjavascript
6
3
December 23, 2017
🌐
SheCodes
shecodes.io › athena › 8931-creating-a-string-with-variables-in-javascript
[JavaScript] - Creating a String With Variables in | SheCodes
Learn how to add a variable to a string using either string concatenation or string interpolation with template literals for a more modern approach.
🌐
GitHub
github.com › EQuimper › CodeChallenge › blob › master › javascript › FreeCodeCamps › Basic JavaScript › Appending Variables to Strings.md
CodeChallenge/javascript/FreeCodeCamps/Basic JavaScript/Appending Variables to Strings.md at master · EQuimper/CodeChallenge
Set someAdjective and append it to myStr using the += operator. // Example var anAdjective = "awesome!"; var ourStr = "Free Code Camp is "; ourStr += anAdjective; // Only change code below this line var someAdjective; var myStr = "Learning to ...
Author   EQuimper
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › string-concat
3 Ways to Concatenate Strings in JavaScript - Mastering JS
The + and += operators are fast on modern JavaScript engines, so no need to worry about something like Java's StringBuilder class.
🌐
W3Schools
w3schools.com › jsref › jsref_concat_string.asp
JavaScript String concat() Method
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST
Find elsewhere
🌐
CoreUI
coreui.io › blog › how-to-concatenate-a-strings-in-javascript
How to concatenate a strings in JavaScript? · CoreUI
April 4, 2024 - const string1 = 'Hello' const string2 = 'world' console.log(string1.concat(' ', string2)) // 'Hello world' Simple concatenations: Opt for the + operator. Embedding variables or expressions: Template literals are your best bet for readability and ease of use. Combining array elements: The join method excels here, especially with custom separators. Appending multiple values: Consider concat for its ability to handle multiple string values at once.
🌐
DEV Community
dev.to › sprite421 › adding-variables-into-strings-using-javascript-s-template-literals-16m2
Adding Variables into Strings using JavaScript's Template Literals - DEV Community
December 20, 2020 - Those methods of logging our variables are valid, but there is another syntax that you might find useful. It's called a template literal. One of its features allows us to include the values of variables in a string.
🌐
TechOnTheNet
techonthenet.com › js › string_concat.php
JavaScript: String concat() method
In JavaScript, concat() is a string method that is used to concatenate strings together. The concat() method appends one or more string values to the calling string and then returns the concatenated result as a new string.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Learn_web_development › Core › Scripting › Strings
Handling text — strings in JavaScript - Learn web development | MDN
Strings declared using single quotes and strings declared using double quotes are the same, and which you use is down to personal preference — although it is good practice to choose one style and use it consistently in your code. Strings declared using backticks are a special kind of string called a template literal. Template literals mostly behave the same as normal strings, but they have some special properties: You can embed JavaScript in them. You can declare template literals over multiple lines. Inside a template literal, you can wrap JavaScript variables or expressions inside ${ }, and the result will be included in the string:
🌐
TutorialsPoint
tutorialspoint.com › How-to-concatenate-multiple-string-variables-in-JavaScript
How to concatenate multiple string variables in JavaScript?
August 8, 2022 - The easiest method to concatenate two strings is to use the template literals. Generally, programmers use the + operator to add two or more numbers, but when we use the + operator with the string variables, it simply merges the two strings.
🌐
freeCodeCamp
freecodecamp.org › news › javascript-string-concatenation
How JavaScript String Concatenation Works – the "+" Operator vs the "+=" Operator
September 7, 2023 - Here, I have provided two separate strings in a single string variable, but I used the plus ( + ) operator to append the second string at the end of the first string.
🌐
Scaler
scaler.com › home › topics › 4 ways to concatenate strings in javascript
4 Ways to Concatenate Strings in JavaScript - Scaler Topics
January 6, 2024 - The value of the result variable is printed as output indicating the use-case of the '+' operator. In this example, we have initialized four strings at the start, and then using the '+=' operator, we are appending strings - Instagram, Twitter, and Facebook to the end of the string result, and the final result string will again be stored in the result variable.
🌐
Turing
turing.com › kb › guide-to-string-concatenation-in-js
Your Guide to String Concatenation in JavaScript
The variable substitution method of template literals is one of the best ways to concatenate strings in JavaScript.
🌐
Delft Stack
delftstack.com › home › howto › javascript › javascript append to string
How to Append to String in JavaScript | Delft Stack
March 11, 2025 - Here’s an example of how to use ... ... Hello, world! In this code snippet, we again defined string1 and string2. By using the + operator, we combined the two strings into a new variable called result....
🌐
IQCode
iqcode.com › code › javascript › how-to-concatenate-strings-and-variables-in-javascript
how to concatenate strings and variables in javascript Code Example
November 9, 2021 - vascript concat string with number js how to join two strings in javascript variable concatenation in javascript how to concat url with staing in javascript string add '//(' nodejs but concated just one '/' combining two strings javascript concatenate javascript with html add get data to a string js JavaScript variable add to string with $ JavaScript variable add to string concat string and int javascript adding two strings together javascript concat strings js javascript concat 3 strings string concat node string concatnation javascript javascript string cat js concat user input add var to st