var myCoolString = myCoolObject.a + '-' + myCoolObject.b + '-' + myCoolObject.c;

EDIT:

With ES6, you can use template strings to interpolate numbers into strings:

let myCoolString = `${myCoolObject.a}-${myCoolObject.b}-${myCoolObject.c}`;

Try it:

var myCoolObject = {
  a: 0,
  b: 12,
  c: 24
};

var myCoolString = myCoolObject.a + '-' + myCoolObject.b + '-' + myCoolObject.c;

console.log(typeof myCoolString);
console.log(myCoolString);

Answer from rink.attendant.6 on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Learn_web_development › Core › Scripting › Strings
Handling text — strings in JavaScript - Learn web development | MDN
You might expect this to return an error, but it works just fine. How numbers should be displayed as strings is fairly well-defined, so the browser automatically converts the number to a string and concatenates the two strings.
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › string-concat
3 Ways to Concatenate Strings in JavaScript - Mastering JS
You can concatenate strings in JavaScript using the `+` operator, the `Array#join()` function, or the `String#concat()` function. Here's what you need to know.
🌐
Quora
quora.com › How-do-you-concatenate-a-number-and-string-in-JavaScript
How to concatenate a number and string in JavaScript - Quora
Answer (1 of 3): So let’s say you want to concatenate the string “Zip Code:” with the number 44893. The code should look similar to this. [code]let st = “Zip Code: “; let nm = 44893; document.getElementById(“test”) = st + nm; [/code]
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"
🌐
Reddit
reddit.com › r/learnjavascript › does javascript concatenate as string when adding a number to a string literal?
r/learnjavascript on Reddit: Does JavaScript concatenate as string when adding a number to a string literal?
November 11, 2023 -

From my understanding of what I've read, the expected behavior is that JavaScript will convert the integer into string, and then add the string to string, which then results in a string concatenation. Therefore...

var addit = 6 + “5”;

...should output... "65";

However, attempting to evulate this in console instead gives the result...

Uncaught SyntaxError: Invalid or unexpected token

Why is this the case?

🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-concatenate-two-numbers
How to Concatenate Two Numbers in JavaScript | bobbyhadz
Copied!const num1 = 1; const num2 ... operator to concatenate two numbers. When used with a number and a string, the + operator concatenates them....
🌐
Mimo
mimo.org › glossary › javascript › string-concatenation
JavaScript String Concatenate: Syntax, Usage, and Examples
Combine text dynamically using JavaScript string concatenation. Use +, concat(), or template literals to format output, build messages, or personalize content.
Find elsewhere
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › concat
String.prototype.concat() - JavaScript | MDN
The concat() method is very similar to the addition/string concatenation operators (+, +=), except that concat() coerces its arguments directly to strings, while addition coerces its operands to primitives first.
🌐
RSWP Themes
rswpthemes.com › home › javascript tutorial › how to concatenate string with integer in javascript
How To Concatenate String With Integer In Javascript
March 28, 2024 - The + operator is a commonly used method for concatenation in JavaScript. When used to concatenate a string with an integer, the operator automatically converts the integer to a string before combining them.
🌐
W3Schools
w3schools.com › jsref › jsref_concat_string.asp
JavaScript String concat() Method
The concat() method returns a new string. ... let text1 = "Hello"; let text2 = "world!"; let text3 = "Have a nice day!"; let result = text1.concat(" ", text2, " ", text3); Try it Yourself » ... If you want to use W3Schools services as an ...
🌐
Delft Stack
delftstack.com › home › howto › javascript › javascript concatenate string and int
How to Concatenate String and Integer in JavaScript | Delft Stack
February 2, 2024 - The expression (apples + oranges) adds the two numbers together, resulting in 8. We then apply the toString() method to convert it to the string "8". This string is then concatenated with the string "Total fruit count: " using the + operator, forming the variable totalFruit, which will hold the string "Total fruit count: 8".
🌐
Andrew Lock
andrewlock.net › when-concatenated-strings-turn-into-numbers-in-javascript
Fixing a bug: when concatenated strings turn into numbers in JavaScript
November 11, 2016 - The rogue + was attempting to convert the string <strong>Details: </strong><span> to a number, was failing and returning NaN. This was then coerced to a string as a result of the subsequent concatenations, and broke my HTML! Removing that + fixed everything. As an interesting side point to this, I was using gulp-uglify to minify the resulting javascript as part of the build.
🌐
EyeHunts
tutorial.eyehunts.com › home › javascript concatenate string and int | example code
JavaScript concatenate string and int | Example code - EyeHunts
May 15, 2021 - You can directly add string and number in JavaScript, no need for a special method or typecasting. Just use a + (Adds two operands) OR += operator to Concatenate integer variable to a string variable.
🌐
Copahost
copahost.com › home › concatenate strings in javascript: quick guide
Concatenate strings in Javascript: Quick guide - Copahost
May 31, 2020 - We concatenated these three variables into a string using the (+) sign. The result of this concatenation is also a string, i.e “string100true”. Remember, In javascript, anything concatenated with a string is always a 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 - We can either create a new string using the '+' operator or we can use an existing string by appending to the end of it, using the '+=' operator. Let's understand this concept using some example codes: In this JavaScript example, we are using ...
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › String › concat
JavaScript String concat() - Concatenate Strings | Vultr Docs
November 14, 2024 - ... let str = "Result: "; let result ... undefined". The concat() function in JavaScript offers a seamless and effective way to join strings, whether you're dealing with text, numbers, or other data types....
🌐
TechOnTheNet
techonthenet.com › js › string_concat.php
JavaScript: String concat() method
This is the concatenation of the string 'Tech' + 'On' + 'The' + 'Net'. The value of the original totn_string variable has not changed and is still equal to 'Tech'. You can use the concat() method with an empty string variable to concatenate primitive string values.
🌐
Intellipaat
intellipaat.com › home › blog › javascript string concatenation
JavaScript String Concatenation: 5 Easy to Combine Strings
December 17, 2025 - Learn how to concatenate strings in JavaScript using +, concat(), join(), and template literals with syntax, examples, best practices, and tips.