JavaScript(拼接)

字符串拼接

双引号配合单引号做拼接练习

     let num = 100;

    // let x = "我有" + num*2 + "块钱";

    // let x = "我说:'小明身上有" + num*3 + "块钱'。";

    // let x = "<p>num</p>";
    // let x = "<p>" +num*50+ "</p>";

    let x = "<p style='" +num+ "px;'></p>";


    console.log(x);

模板字符串拼接

    let a = 10;
    let b = 20;

    // let c = `hhh`+a*b+`ggg`

    let c = `hhh${a}ggg`;

    console.log(c);

${}中填写运算结果

原文地址:https://www.cnblogs.com/yhy-blog/p/14233361.html