GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing zh.javascript.info — 字符串的反引号

  • 教程
  • JavaScript 编程语言
  • JavaScript 基础知识
  • 数据类型
回到课程

字符串的反引号

重要程度: 5

下面的脚本会输出什么?

let name = "Ilya";

alert( `hello ${1}` ); // ?

alert( `hello ${"name"}` ); // ?

alert( `hello ${name}` ); // ?

反引号将包装在 ${...} 中的表达式嵌入到了字符串。

let name = "Ilya";

// 表达式为数字 1
alert( `hello ${1}` ); // hello 1

// 表达式是一个字符串 "name"
alert( `hello ${"name"}` ); // hello name

// 表达式是一个变量,嵌入进去了。
alert( `hello ${name}` ); // hello Ilya
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.