I am having difficulties concatenating strings in TypeScript.
Code:
var info= {user:'med'};
console.log('le nom est:${info.user}');
The result is:
le nom est:${info.user}
How do I concatenate 2 strings in TypeScript?
The concat() is an inbuilt function in TypeScript which is used to add two or more strings and returns a new single string. Syntax: string. concat(string2, string3[, ..., stringN]);
In TypeScript, the string is sequence of char values and also considered as an object. It is a type of primitive data type that is used to store text data. The string values are used between single quotation marks or double quotation marks, and also array of characters works same as a string.
To concatenate two numbers in JavaScript, add an empty string to the numbers, e.g. "" + 1 + 2 . When using the addition operator with a string and a number, it concatenates the values and returns the result. Copied! We used the addition (+) operator to concat two numbers.
With a template string:
console.log(`The name is: ${info.user}`);
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