编程语言
首页 > 编程语言> > JavaScript(拼接)

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='width:" +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);

${}中填写运算结果

标签:num,log,JavaScript,ggg,拼接,let,hhh
来源: https://www.cnblogs.com/yhy-blog/p/14233361.html