How do I put variables inside javascript strings?

前端 未结 13 1090
感动是毒
感动是毒 2020-12-12 15:12
s = \'hello %s, how are you doing\' % (my_name)

That\'s how you do it in python. How can you do that in javascript/node.js?

13条回答
  •  时光说笑
    2020-12-12 16:00

    Here is a Multi-line String Literal example in Node.js.

    > let name = 'Fred'
    > tm = `Dear ${name},
    ... This is to inform you, ${name}, that you are
    ... IN VIOLATION of Penal Code 64.302-4.
    ... Surrender yourself IMMEDIATELY!
    ... THIS MEANS YOU, ${name}!!!
    ...
    ... `
    'Dear Fred,\nThis is to inform you, Fred, that you are\nIN VIOLATION of Penal Code 64.302-4.\nSurrender yourself IMMEDIATELY!\nTHIS MEANS YOU, Fred!!!\n\n'
    console.log(tm)
    Dear Fred,
    This is to inform you, Fred, that you are
    IN VIOLATION of Penal Code 64.302-4.
    Surrender yourself IMMEDIATELY!
    THIS MEANS YOU, Fred!!!
    
    
    undefined
    >
    

提交回复
热议问题