Using the concat()
method in TypeScript is similar to JavaScript. We can use this method to concatenate two or more strings on the go.
string1.concat(string2, stringg3, ... stringN)
string1
: This is the string we want to concatenate with other strings.string2, string3, ... stringN
: These are the strings we want to concatenate with string1
. It can be one or more.It returns a string. This string is a concatenation of all the strings we joined using the concat()
method.
export {}// create some strings.let name:string = "Theodore"let role:string = "Software Developer"let nickName:string = "Kcee"let hubby:string = "Coding"// concatenate these stringslet fullString = name.concat(" is a ", role, " with a nickname ",nickName, ". He loves ", hubby)// log out the concatenated stringsconsole.log(fullString)