0

How to turn this:

api.viewerUrl + (utils.includes(api.historyModeServers, api.env) ? '/' : '/#!/') + buildingId

Into string interpolation? (Using ${}).

3
  • Are you using ES6? Commented Aug 1, 2017 at 6:14
  • @TrishantPahwa Yes. Commented Aug 1, 2017 at 6:15
  • You can also check out the docs on template literals. Commented Aug 1, 2017 at 7:10

2 Answers 2

1

Remove '+' and wrap expressions with ${}. Ternary operator is expression as well.

`${api.viewerUrl}${utils.includes(api.historyModeServers, api.env) ? '/' : '/#!/'}${buildingId}`
Sign up to request clarification or add additional context in comments.

Comments

1

separate conditional expression would be good practice. easier to read and maintain.

let words = (utils.includes(api.historyModeServers, api.env) ? '/' : '/#!/');
let str = `${api.viewerUrl}${words}${buildingId}`;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.