文章目录
字符串新的api
- 字符串新的api
- 字符串模板
- 字符串模板引入函数
字符串扩展的方法
let str = "hello.vue";
console.log(str.startsWith("hello"));
console.log(str.endsWith(".vue"));
console.log(str.includes("e"));
console.log(str.includes("hello"));
控制台打印如下
用反引号, 除了定义字符串, 还可以在字符串中加入变量和表达式
let ss = `
hello world
`
字符串插入变量和表达式, 变量名写在{} 中, ${} 中可以放入js表达式
let abc = "周杰伦";
let age = 8 ;
let info = `我是${abc},今年${age+10}岁了`;
console.log(info);
function fun(){
return "我今天又进步了! "
}
let abc = "周杰伦";
let age = 8 ;
let infos = `我是${abc},今年${age+10}岁了, 我想说 : ${fun()}`;
console.log(infos);