zoukankan      html  css  js  c++  java
  • js模板字符串

    ES6中引入了模板字符串,让我们告别了使用大量'' 和 +来连接字符串了写法。

    要创造一个模板字符串,只需要使用反引号``将字符串包起来,模板字符串中的变量用${变量名}替代即可

    var a = 'o,';var b = 'd!'
    console.log (`Hell${a}worl${b}`);
    // Hello,world!

    1、多行字符串

    在模板字符串内,换行和空格是会保存并展示出来的

    var a = 'o,';var b = 'd!'
    console.log(`Hell${a}
    worl${b}`);
    /*
    Hello,
    world!
    */

    2、嵌入表达式

    var a = 1; b = 2;
    console.log (`${a} + ${b} = ${a + b} `)
    //1 + 2 = 3
    1
    2
    3
    3、调用函数

    function string(){
    return "Hello!";
    }
    console.log(`${string()} world!`);
    //Hello! world!

      

    勤学似春起之苗,不见其增,日有所长; 辍学如磨刀之石,不见其损,日所有亏!
  • 相关阅读:
    mysql find_int_set
    PHPSTROM8.0 注册码(7.1也可用)
    gym 101657 D
    gym101657 C
    poj 3525
    poj1279
    poj3335
    poj 1228
    poj 1873
    poj 2074
  • 原文地址:https://www.cnblogs.com/qiaozhiming123/p/14591550.html
Copyright © 2011-2022 走看看