String concatenation has been a real pain in JavaScript compared to other programming languages but ES-6 has worked around this limitation by introducing template literals which are a cool way of concatenating strings.
<script type="text/javascript"> var message="This is a test"; //Old style using + operator console.log("Hi " + message); //New style (using backtick not single quote) console.log(`Hi ${message}`); //If you just want to print entire string and not evaluate it use backslash \ console.log(`Hi \${message}`); </script>
Output:
Hi This is a test
Hi This is a test
Hi ${message}