Build a formatted string with embedded expressions using backtick interpolation.

← Operators and Expressions · Ref: Q1164

Backtick strings with ${expr} for interpolation:

  stdout.println(`Name: ${name}, Age: ${age}`)
  stdout.println(`Total: ${price * quantity}`)

$ inside backticks is the interpolation marker, not the $ string operator. See Q909, Q918.

Example

defines module qa.operators.interpolationpatterns

  defines program

    InterpolationPatternsDemo()
      stdout <- Stdout()

      name <- "Alice"
      age <- 30
      price <- 9.99
      quantity <- 3

      //Basic interpolation
      stdout.println(`Name: ${name}, Age: ${age}`)

      //Arithmetic inside ${}
      stdout.println(`Total: ${price * quantity}`)

      //Multiple expressions
      stdout.println(`${name} is ${age} years old`)

Common mistakes

E11068 — EK9 forbids 3+ part string concatenation with '+'; use backtick interpolation instead. See ek9 -h E11068 for details.

Incorrect:

stdout.println("Name is " + name + " today")

Correct:

stdout.println(`Name: ${name}, Age: ${age}`)
Other ways to ask this
  • I need to embed variable values and arithmetic inside a string
  • In JavaScript I'd use template literals with ${}. Write the EK9 interpolation
  • Given name, age, and a calculation, build a formatted output string
  • Construct a display string with multiple embedded expressions

Coming from another language?

JavaScript: `Hello ${name}`. Kotlin: "Hello $name". Python: f"Hello {name}". EK9: `Hello ${name}` — same as JavaScript.

Keywords: string, format, template, backtick, interpolation, embed