{
console.log(‘a‘,`\u0061`);
console.log(‘s‘,`\u20BB7`);
console.log(‘s‘,`\u{20BB7}`);
}
{
let s=‘??‘;
console.log(‘length‘,s.length);
console.log(‘0‘,s.charAt(0));
console.log(‘1‘,s.charAt(1));
console.log(‘at0‘,s.charCodeAt(0));
console.log(‘at1‘,s.charCodeAt(1));
let s1=‘??a‘;
console.log(‘length‘,s1.length);
console.log(‘code0‘,s1.codePointAt(0));
console.log(‘code0‘,s1.codePointAt(0).toString(16));
console.log(‘code1‘,s1.codePointAt(1));
console.log(‘code2‘,s1.codePointAt(2));
}
{
console.log(String.fromCharCode("0x20bb7"));
console.log(String.fromCodePoint("0x20bb7"));
}
{
let str=‘\u{20bb7}abc‘;
for(let i=0;i<str.length;i++){
console.log(‘es5‘,str[i]);
}
for(let code of str){
console.log(‘es6‘,code);
}
}
// includes 用来判断一个数组是否包含一个指定的值
// startsWith 返回布尔值,表示参数字符串是否在原字符串的头部
// endsWith 返回布尔值,表示参数字符串是否在原字符串的尾部
{
let str="string";
console.log(‘includes‘,str.includes("c"));
console.log(‘start‘,str.startsWith(‘str‘));
console.log(‘end‘,str.endsWith(‘ng‘));
}
// repeat 复制
{
let str="abc";
console.log(str.repeat(2));
}
{
let name="list";
let info="hello world";
let m=`i am ${name},${info}`;
console.log(m); //i am list hello world
}
// padStart 在···不满足第一个参数的时候,在‘1’之前添加0
// padEnd 在···不满足第一个参数的时候,在‘1’之后添加0
{
console.log(‘1‘.padStart(2,‘0‘));
console.log(‘1‘.padEnd(2,‘0‘));
}
{
let user={
name:‘list‘,
info:‘hello world‘
};
console.log(abc`i am ${user.name},${user.info}`);
function abc(s,v1,v2){
console.log(s,v1,v2);
return s+v1+v2
}
}
{
console.log(String.raw`Hi\n${1+2}`);
console.log(`Hi\n${1+2}`);
}
原文地址:https://www.cnblogs.com/lujieting/p/10727163.html