美文网首页
标签模板字符串

标签模板字符串

作者: 未路过 | 来源:发表于2022-10-28 21:36 被阅读0次
          // ES6: 标签模板字符串
          const name = "why";
          const age = 18;
    
          // 1.模板字符串的基本使用
          const str = `my name is ${name}, age is ${age}`;
          console.log(str); //my name is why, age is 18
    
          // 2.标签模板字符串的使用
          function foo(...args) {
            console.log(args);
          }
    
          foo("why", 18, 1.88); // ['why', 18, 1.88]
    
          foo`my name is ${name}, age is ${age}`;
          // [Array(3), 'why', 18]
          //0: (3) ['my name is ', ', age is ', '', raw: 0:Array(3)]
    //1: "why"
    //2: 18
    
    image.png

    相关文章

      网友评论

          本文标题:标签模板字符串

          本文链接:https://www.haomeiwen.com/subject/iisctdtx.html