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.
Hey Mohan C, thanks so much for reading!
You’re definitely right that it can be easier at times to read “simple” string concatenation just using the
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>"
Thanks so much for taking the time to respond! Cheers!