An official familiar with the K League transfer market said on the 30th, “Gangwon FC is about to recruit Brazilian striker baseball Cariello (24, Yago Cariello, photo).” Cariello was the top scorer…
There are multiple ways in JavaScript to append variable value to a string. But, the most easy way to do it is by using Template Literal.
First we will discuss other ways how we can achieve the same thing that template literals provides.
There are three ways to append any value to string in JavaScript.
Using Double Quote:-
Using Double quote we can append value to a string using + sign but it becomes difficult when we want to append multiple values and in the middle of the string value. Sometimes we want to display some part of the string in new line that is possible but it makes the code more complicated to understand. Below is an example where we have achieved all the things using double quote.
Example:-
Output:-
As you can see that it is very complicated to understand above program.
Single Quote:-
The above output can be achieved with single quote as well but the complication level will be same. So let’s do that as well.
Example:-
Output:-
As you can see the complication is same only just double quote is being replaced with the single quote.
Template Literal:-
Now we will see how we can achieve the same output with back ticks with no complicated code.
Output:-
As you can see we don’t have to provide + sign and not even \n to write in new line. It will print the message as given in the code so if you want to print some string in new line then just write it in a new line. To append any value just put value in ${} and even you can write JavaScript code inside it.
Thank you for reading please comment your suggestions, share the article, follow me and Abhima JavaScript publication.
लभन्ते ब्रह्मनिर्वाणमृषय: क्षीणकल्मषा: |
छिन्नद्वैधा यतात्मान: सर्वभूतहिते रता: || 25||
labhante brahma-nirvāṇam ṛiṣhayaḥ kṣhīṇa-kalmaṣhāḥ
chhinna-dvaidhā yatātmānaḥ sarva-bhūta-hite ratāḥ
Rumah Harapan Indonesia atau yang lebih sering disebut sebagai RHI yang didirikan di Semarang pada tahun 2017 ini adalah salah satu cabang RHI Jakarta, yang merupakan rumah singgah untuk anak-anak…
In my study duration , i have joined a training session named Foster Flagship Training program which is for youth specifically. We got assigned a project “Trees Plantation” in which we have to plant…
Tenho pensado muito sobre o corpo. Não é de hoje, na verdade, faz tempo que o corpo é um negócio que me assusta. Essa estrutura intrincada, complexa, meticulosa, essa espécie de engrenagem onde tudo…