02-ES6模板字符.html 648 B

12345678910111213141516171819202122
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. var star = {
  11. name: "刘德华",
  12. age: 18
  13. };
  14. // 以前的写法 拼接的时候引号很容易出问题
  15. console.log("我的名字是" + star.name + "我的年龄是" + star.age);
  16. // ES6 模板字符写法
  17. console.log(`我的名字是${star.name}
  18. 我的年龄是${star.age}`);
  19. console.log(`<span>${star.name}</span><span>${star.age}</span>`);
  20. </script>
  21. </body>
  22. </html>