2021-06-15 00:49:18 -07:00
---
id: 56533eb9ac21ba0edf2244b7
2021-07-21 20:53:20 +05:30
title: Concatenar strings com o operador mais
2021-06-15 00:49:18 -07:00
challengeType: 1
videoUrl: 'https://scrimba.com/c/cNpM8AN'
forumTopicId: 16802
dashedName: concatenating-strings-with-plus-operator
---
# --description--
2021-07-26 23:39:21 +09:00
Em JavaScript, quando o operador `+` é usado com um valor de `String` , ele é chamado de operador de < dfn > concatenação</ dfn > . Você pode criar uma nova string a partir de outras strings ao < dfn > concatenar</ dfn > elas juntos.
2021-06-15 00:49:18 -07:00
2021-07-09 21:23:54 -07:00
**Exemplo**
2021-06-15 00:49:18 -07:00
```js
'My name is Alan,' + ' I concatenate.'
```
2021-07-26 23:39:21 +09:00
**Observação:** cuidado com os espaços. A concatenação não adiciona espaços entre strings concatenadas, então você mesmo precisará adicioná-las.
2021-06-15 00:49:18 -07:00
2021-07-09 21:23:54 -07:00
Exemplo:
2021-06-15 00:49:18 -07:00
```js
var ourStr = "I come first. " + "I come second.";
```
2021-07-09 21:23:54 -07:00
A string `I come first. I come second.` seria exibida no console.
2021-06-15 00:49:18 -07:00
# --instructions--
2021-07-26 23:39:21 +09:00
Crie `myStr` a partir das strings `This is the start.` e `This is the end.` usando o operador `+` .
2021-06-15 00:49:18 -07:00
# --hints--
2021-07-09 21:23:54 -07:00
`myStr` deve ter o valor da string `This is the start. This is the end.`
2021-06-15 00:49:18 -07:00
```js
assert(myStr === 'This is the start. This is the end.');
```
2021-07-26 23:39:21 +09:00
Você deve usar o operador `+` para criar `myStr` .
2021-06-15 00:49:18 -07:00
```js
assert(code.match(/(["']).*\1\s*\+\s*(["']).*\2/g));
```
2021-07-26 23:39:21 +09:00
`myStr` deve ser criada usando a palavra-chave `var` .
2021-06-15 00:49:18 -07:00
```js
assert(/var\s+myStr/.test(code));
```
2021-07-09 21:23:54 -07:00
Você deve atribuir o resultado à variável `myStr` .
2021-06-15 00:49:18 -07:00
```js
assert(/myStr\s*=/.test(code));
```
# --seed--
## --after-user-code--
```js
(function(){
if(typeof myStr === 'string') {
return 'myStr = "' + myStr + '"';
} else {
return 'myStr is not a string';
}
})();
```
## --seed-contents--
```js
var myStr; // Change this line
```
# --solutions--
```js
var myStr = "This is the start. " + "This is the end.";
```