-1

I want to know how to make string interpolation like in Ruby but in Javascript

name = "world"
puts "Hello, #{name}!"
Julie
  • 34
  • 3

1 Answers1

3

You can use template literals by using ` (sorry, can't put it in block code) instead of " or ':

let name = "world";
console.log("Hello, " + name); // Classical way
console.log(`Hello, ${name}`); // With template literals
brk
  • 46,805
  • 5
  • 49
  • 71
IndiGan
  • 76
  • 8