模板字符串取代了原有的字符串拼接功能
let name = 'qsqs';
let age = 9;
let str = `hello,${name}今年${age}岁了`;
console.log(str);
-----------------------------------------------------------
let ul =
`<ul>
<li>${name}</li>
<li>${age}</li>
</ul>`;
console.log(ul);
---------------------------------------
let a='qsqsqsqs';
let b =99;
let str = `hello${a}今年${b}岁了`;
str = str.replace(/\$\{([^}]*)\}/g, function(){
return eval(arguments[1]);
})
console.log(str);
---------------------------------------------------------------------
let a='qsqsqsqs';
let b =99;
function qs(){
let strings = arguments[0];
let values = [].slice.call(arguments, 1);
let str ='';
for(let i = 0; i < values.length; i++){
str+=`${strings[i]}*${values[i]}*`;
}
str += strings[strings.length - 1];
return str;
}
let str = qs`hello${a}今年${b}岁了`;
console.log(str);
---------------------------------------------------------------------
let url = 'http://www.dnajndkjdk.cn/log.png';
console.log(url.includes('dna'));
console.log(url.startsWith('http://'));
console.log(url.endsWith('.png'));
setInterval(() => {
let date = new Date();
let hour = date.getHours();
let minutes = date.getMinutes();
let seconds = date.getSeconds();
let str = `${hour.toString().padStart(2,0)}`;
str += `:${minutes.toString().padStart(2,0)}`;
str += `:${seconds.toString().padStart(2,0)}`;
console.log(str);
}, 1000);