Various Coding Languages: String Interpolation

Post Reply
User avatar
Jason
Site Admin
Posts: 749
Joined: Tue Jul 01, 2025 10:13 am

Various Coding Languages: String Interpolation - # 2
There are different ways to interpolate in certain different languages to simplify spacing and printing out variables.

JavaScript

Code: Select all

<html>

<head></head>

<body>

<script>

var a_certain_animal_species = "dog";

window.alert("The ${a_certain_animal_species} is a popular companion in many cultures.");

window.alert("The" + " " + a_certain_animal_species + " " + "is a popular companion in many cultures.")

</script>

</body>

</html>


Php

Code: Select all


<html>

<head></head>

<body>

<?php

$a_certain_candy_type = "caramel";

echo "Some people like {$a_certain_candy_type}.";

echo 'Some people like' . ' ' . $a_certain_candy_type + '.';

echo "Some people like $a_certain_candy_type.";

?>

</body>

</html>

 

POSTREACT(ions) SUMMARY

Post Reply