To make a string out of a string and a passed variable in JS use concatenation to combine the variable to another string.
Simply just add a plus sign+ between the strings or string variables you want to connect.
<script> let animal = 'Horse'; console.log('My favorite animal is the ' + animal + '.'); </script>
HTML example code:-
<html> <body> <script> let animal = 'Horse'; console.log('My favorite animal is the ' + animal + '.'); var day = "6" console.log("Today day is " + day); </script> </body> </html>
Note: You can use a single quote or a double quote it doesn’t matter as long as your opening and closing quotes are the same.
Do comment if you have any doubts and suggestions on this Variable and string topic of JS.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.