DEV Community

Discussion on: Three dots ( … ) in JavaScript

Collapse
 
mylastore profile image
Oscar Quinteros

First of all, thank you for this tutorial. What are the three dots doing on the code below?

const api = (method, path, data, token) => {
if(method === "GET" || method === "DELETE"){
return fetch(${API}/${path}, {
method: ${method},
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
...(token ? { Authorization: Bearer ${token} } : {})
},
})
.then(res => {
return res.json()
})
.catch(error => console.log(error))
}

Collapse
 
sagar profile image
Sagar

if a token is present then it will add Authorization: Bearer ${token} to headers else it will not add anything

Collapse
 
peterlitszo profile image
peterlits zo • Edited

Well, you can try markdown's code block with three '`' at the code's begin and end.

Wait why it do not have code block?