首页 > 解决方案 > 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

标签: javascriptstring

解决方案


要使用此功能,您必须使用 backtics:

const name = "Stephen";
document.write(`Hey ${name} how are you?`);

推荐阅读