Blogger Information
Blog 12
fans 0
comment 0
visits 8881
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
2020-05-30——String
A 枕上人如玉、
Original
646 people have browsed it

使用反引号”`”

使用``将字符串包起来,可以解决下面的问题:

字符串不能换行,如果换行只能使用+号
字符串中的引号如果和最外层相同,需要进行转义

字符串中插入变量,需要用+号 以前这样的写法:

  1. var name = 'world'
  2. var str = "小明说:\"hello, " + name + "\""
  3. // 小明说:"hello, world"

现在可以方便的写作:

  1. var name = 'world'
  2. str str = `小明说:"hello, ${name}"

总的来说,有三个好处:

不怕字符串中出现的引号;
不怕换行,反引号包起来的字符串可以随便换行;
使用${}将变量或表达式包起来直接放在字符串中,不用写很多+

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post