In JavaScript, you can concatenate (combine) two strings using the `+` operator. Here's an example:
let string1 = "Hello, ";let string2 = "world!";let result = string1 + string2;console.log(result); // Outputs: Hello, world!
In this example, the `+` operator is used to concatenate `string1` and `string2` to create a new string stored in the variable `result`. The resulting string contains the contents of both `string1` and `string2` combined.
You can also concatenate multiple strings in a single expression:
let greeting = "Hello, ";let userName = "John";let punctuation = "!";let fullGreeting = greeting + userName + punctuation;console.log(fullGreeting); // Outputs: Hello, John!
Remember that the `+` operator, when used with strings, is the concatenation operator. If one or both of the operands are not strings, JavaScript will convert them to strings before performing the concatenation.
Social Plugin