interpolation
const name = "bob";
const age = 21;
const message = `${name} is ${age} years old`;
console.log(message);
1
2
3
4
5
2
3
4
5
Output
bob is 21 years old
1
# Go
package main
import "fmt"
func main() {
name := "bob"
age := 21
message := fmt.Sprintf("%s is %d years old", name, age)
fmt.Println(message)
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
Output
bob is 21 years old
1
编辑 (opens new window)
上次更新: 2022/09/30, 11:34:22