JavaScript equivalent of Python's format() function?

前端 未结 17 2080
慢半拍i
慢半拍i 2020-12-13 08:42

Python has this beautiful function to turn this:

bar1 = \'foobar\'
bar2 = \'jumped\'
bar3 = \'dog\'

foo = \'The lazy \' + bar3 + \' \' + bar2 \' over the \'         


        
17条回答
  •  粉色の甜心
    2020-12-13 09:12

    You can use template literals in JS,

    const bar1 = 'foobar'
    const bar2 = 'jumped'
    const bar3 = 'dog'
    foo = `The lazy ${bar3} ${bar2} over the ${bar1}`
    

    I think this was helpful.

提交回复
热议问题