Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

typescript
concat
string
communitycreator
method

What is the string.concat() method in TypeScript?

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

Using the concat() method in TypeScript is similar to JavaScript. We can use this method to concatenate two or more strings on the go.

Syntax

string1.concat(string2, stringg3, ... stringN)
Syntax for concat() method in TypeScript

Parameters

  • 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.

Return value

It returns a string. This string is a concatenation of all the strings we joined using the concat() method.

Example

export {}
// create some strings.
let name:string = "Theodore"
let role:string = "Software Developer"
let nickName:string = "Kcee"
let hubby:string = "Coding"
// concatenate these strings
let fullString = name.concat(" is a ", role, " with a nickname ",
nickName, ". He loves ", hubby)
// log out the concatenated strings
console.log(fullString)
Concatenate two or more strings in TypeScript with the concat() method

Explanation

  • Line 1: We export our file as a module.
  • Lines 4–7: We create some strings. These are the strings we want to concatenate.
  • Lines 10–11: We concatenate the strings with some other strings.
  • Line 14: We log out the concatenated string.

RELATED TAGS

typescript
concat
string
communitycreator
method

CONTRIBUTOR

Theodore Kelechukwu Onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring