javascript - Why my E6 code ${"name"}; isn't working as supposed?
问题描述
When I type this code:
const name = "Stephen";
document.write("Hey ${name} how are you?");
All browser shows:
Hey ${name} how are you?
instead of:
Hey Stephen how are you?
What did I do wrong? isn't that E6 feature supposed to work? I tried Safari, chrome and everywhere it shows the same problem
解决方案
要使用此功能,您必须使用 backtics:
const name = "Stephen";
document.write(`Hey ${name} how are you?`);
推荐阅读
- java - 为什么java进程消耗的内存比jcmd输出高得多?
- .net - 如何以编程方式检查 Windows 7 和 Windows 10 上的 .NET 版本?
- jquery - 预先选择了不同的页面单选按钮
- javascript - 单击缩略图图像需要使用 jquery 显示滑块图像
- ejabberd - 使用 1804 二进制安装程序的 raspbian stretch 1609 手动更新不起作用
- azure - Azure 应用服务上的 ASP.NET Core 2.1 RC1 扩展
- asp.net-core - DbContext.set() 无法为实体创建 DbSet,因为此类型未包含在上下文的模型中
- sql - 尝试在使用 MIN(CASE when... 或 MAX(CASE when
- javascript - JavaScript 在标签中显示表格中下拉列表的每个选定值
- python - 如何在 python 3.6 中按不同类拆分数据