xFactorSchool.com
Python
JavaScript
How to Do Examples
C Examples
Python Examples
HTML Examples
Code Examples
C Code Examples
C++ Code Examples
C# Code Examples
Java Code Examples
Python Code Examples
HTML Code Examples
CSS Code Examples
JavaScript Code Examples
Online Compilers
C Compiler
C++ Compiler
C# Compiler
Java Compiler
Python Compiler
HTML Code Editor
CSS Code Editor
JavaScript Compiler
JavaScript Code Editor
Practice how to format (template) string in JavaScript
JavaScript Online Editor
Run Code
More JavaScript Sample Codes
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>String Formatting in JavaScript</title> <!--Script tag is added to write JavaScript code inside it--> <script> //Create an object by using a list of key-value pairs enclosed in curly braces {}. var firstName = "John"; var lastName = "Smith"; var age = 25; function myFunction() { // backticks `` is used for the template string formating and variables are placed inside '${' and '}' document.getElementById("myString").innerHTML = `${firstName} ${lastName} is ${age} years old.`; } </script> </head> <body> <h1>How to format string in JavaScript?</h1> <button onclick="myFunction()">Click here to see result</button> <p id="myString"></p> </body> </html>