That’s a great point — it comes down to personal preference

There’s nothing wrong with using the plus sign + for string concatenation, though it can make HTML hard to read.

Dr. Derek Austin 🥳
1 min readJun 23, 2020

--

Hey , thanks so much for reading!

You’re definitely right that it can be easier at times to read “simple” string concatenation just using the + sign:

const hello = "Hello "
const world = "World!"
console.log(hello + world) // Hello World!

On the other hand, I find it gets a lot messier when you need to include a lot of spaces or other punctuation:

const name = "Mohan"
console.log("Say hello to" + " " + name + " " + "for me!")

And multi-line HTML is basically unreadable, especially if you include indenting in your code:

const someHTML = "<html>\n  <head>\n    <title>A page</title>\n  </head>\n  <body>\n    <p>Wow this is getting hard to read</p>\n  </body>\n</html>"
console.log(someHTML)
document.write(someHTML)

But if that’s still easy for you to read, then be my guest! JavaScript really doesn’t care, and code readability is super important.

Another reader pointed out that webpack or Babel will transpile your code to remove backtick literals anyway, at least if you’re supporting ES5 and IE.

Thanks so much for taking the time to respond! Cheers!

--

--

Dr. Derek Austin 🥳
Dr. Derek Austin 🥳

Written by Dr. Derek Austin 🥳

Hi, I'm Doctor Derek! I've been a professional web developer since 2005, and I love writing about programming with JavaScript, TypeScript, React, Next.js & Git.

No responses yet