This means that you can no longer perform any math operations on them. To combine numbers, use the CONCATENATE or CONCAT, TEXT or TEXTJOIN functions, and the ampersand (&) operator. Notes: In Excel 2016, Excel Mobile, and Excel for the web, CONCATENATE has been replaced with the CONCAT function.
In JavaScript, we can assign strings to a variable and use concatenation to combine the variable to another string. To concatenate a string, you add a plus sign+ between the strings or string variables you want to connect. let myPet = 'seahorse'; console.
The concat() method joins two or more strings. The concat() method does not change the existing strings. The concat() method returns a new string.
Joining multiple strings together is known as concatenation. The concatenation operator. The concatenation operator (+) concatenates two or more string values together and return another string which is the union of the two operand strings. The shorthand assignment operator += can also be used to concatenate strings.
Use "" + 5 + 6
to force it to strings. This works with numerical variables too:
var a = 5;
var b = 6;
console.log("" + a + b);
You can now make use of ES6 template literals.
const numbersAsString = `${5}${6}`;
console.log(numbersAsString); // Outputs 56
Or, if you have variables:
const someNumber = 5;
const someOtherNumber = 6;
const numbersAsString = `${someNumber}${someOtherNumber}`;
console.log(numbersAsString); // Outputs 56
Personally I find the new syntax much clearer, albeit slightly more verbose.
var value = "" + 5 + 6;
alert(value);
just use:
5 + "" + 6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With