var stringA = "hello";
stringA += " world";
"Contains e:" + (stringA.indexOf("e") >= 0) + " length:" + stringA.length
"current time: " + new Date() + "\n" +
"format yyyy/mm/dd: " + new Date('2022/11/30 10:35:32') + "\n" +
"format mm/dd/yyyy: " + new Date('11/30/2022 10:35:32') + "\n" +
"format yyyy-mm-dd: " + new Date('2022-11-30 10:35:32'.replace(/-/g,'/'));
var arrayA = [-1.2, 3.2, 15, 4.912];
arrayA[2];
var cat1 = {color:"white", age:"15", name:"GuaiGuai"};
cat1.name
Math.E
Math.PI
Math.abs(-5.611)
Math.exp(2)
Math.sqrt(9)
Math.pow(27,-3)
Math.pow(2,5)
Math.cos(0)
Math.sin(9)
Math.tan(5)
Math.atan(-7.3)
Math.acos(0.5)
Math.asin(0.3)
Math.log(6)
// ECMAScript 6 supports while ECMAScript 5.1 not support
Math.log10(6)
// ECMAScript 6 supports while ECMAScript 5.1 not support
Math.log2(6)
Math.ceil(4.13)
Math.floor(4.67)
Math.round(4.83)
Math.trunc(4.83)
Math.random()
Math.max(1,2,-3)
Math.min(1,2,-3)
'Hello' == 'hello' || 'a' < 'A' || 'a' != 'A'
"Hello World! World is yourself.".replace("World", "Feeling");
"Hello World! World is yourself.".replace(/World/g, "Feeling");
'Hello'.startsWith('h')
'Hello'.endsWith('o')
'Hello'.substring(2, 5)
'hello'.charAt(2)
'hello'.concat(' world')
'1,2,3,4'.split(',')
'hello'.indexOf('e')
'hello'.lastIndexOf('l')
'hello'.length
var stringA = "abc1233hello";
var regexA = /3{2,}/ig;
stringA.search(regexA)
'Hello'.toLowerCase()
'Hello'.toUpperCase()
var arrayA = [-1.2, 3.2, 15, 4.912];
arrayA.length
var arrayA = [-1.2, 3.2, 15, 4.912];
arrayA.push(-47);
var arrayA = [-1.2, 3.2, 15, 4.912];
arrayA.pop()
var stringA = "abc1233hello";
var regexA = /3{2,}/ig;
stringA.search(regexA) >= 0
var stringA = "abc1233hello";
var regexA = /\S*3{2,}\S*/ig;
stringA.search(regexA) >= 0
var arrayA = ['A', 'B', 'C', 'D'];
arrayA.includes('C');
var v1='hello'
isNaN(v1 - 1)
var arrayA = ['A', 'B', 'C', 'D'];
var stringA = "abc1233hello";
arrayA.includes('C') && (arrayA.length >= 8 || stringA.length < 5 || !stringA.endsWith("h"));
"current time: " + "\n" +
"new Date() = " + new Date()+ "\n" +
"new Date().getTime() = " + new Date().getTime() + "\n" +
"new Date().toLocaleString() = " + new Date().toLocaleString()+ "\n" +
"new Date().toGMTString() = " + new Date().toGMTString()+ "\n" +
"new Date().toISOString() = " + new Date().toISOString()+ "\n" +
"new Date().toUTCString() = " + new Date().toUTCString()+ "\n" +
"new Date().toString() = " + new Date().toString()+ "\n" +
"new Date().toJSON() = " + new Date().toJSON()+ "\n" +
"new Date().toDateString() = " + new Date().toDateString()+ "\n" +
"new Date().toTimeString() = " + new Date().toTimeString()+ "\n" +
"new Date().toLocaleDateString() = " + new Date().toLocaleDateString()+ "\n" +
"new Date().toLocaleTimeString() = " + new Date().toLocaleTimeString()
new Date('2022/11/30 10:35:32').toLocaleString() + "\n" +
new Date('11/30/2022 10:35:32').toLocaleString() + "\n" +
new Date('2022-11-30 10:35:32'.replace(/-/g,'/')).toLocaleString() + "\n" +
new Date('2022/11/30') + "\n" +
new Date('2022-11-30'.replace(/-/g,'/'))
function formatDate(date) {
var y = date.getFullYear();
var m = date.getMonth() + 1;
m = m < 10 ? ('0' + m) : m;
var d = date.getDate();
d = d < 10 ? ('0' + d) : d;
var h =date.getHours();
h = h < 10 ? ('0' + h) : h;
var M =date.getMinutes();
M = M < 10 ? ('0' + M) : M;
var s =date.getSeconds();
s = s < 10 ? ('0' + s) : s;
return y + '-' + m + '-' + d + ' ' + h + ':' + M + ':' + s;
}
formatDate(new Date());
var timeb = new Date('2022/11/30 10:35:32');
"year: " + timeb.getFullYear() + "\nmonth: " + (timeb.getMonth() + 1) + "\nday: " + timeb.getDate()
+ "\nweek day: " + timeb.getDay() + "\nhours: " + timeb.getHours()+ "\nminutes: " + timeb.getMinutes()
+ "\nseconds: " + timeb.getSeconds();
new Date().getDay() == 0
new Date('2012/05/19').getTime() > new Date('2016/05/19 09:23:12').getTime()
function addStyle(style) {
var node = document.createElement("style");
node.id = "mystyleid";
node.type = "text/css";
node.innerHTML = style.replace(/\n/g," ");
document.getElementsByTagName("HEAD").item(0).appendChild(node);
};
addStyle("body { background-color:black; color:#CCFF99; }");
function removeNode(id) {
var node = document.getElementById(id);
if ( node != null )
node.parentNode.removeChild(node);
};
removeNode("mystyleid");
window.getSelection().removeAllRanges();
var selection = window.getSelection();
var range = document.createRange();
range.selectNode(document.documentElement);
selection.addRange(range);
window.getSelection().removeAllRanges();
function selectNode(id) {
window.getSelection().removeAllRanges();
var selection = window.getSelection();
var range = document.createRange();
range.selectNode(document.getElementById(id));
selection.addRange(range);
};
selectNode("someid");
window.getSelection().toString();
var selectionObj = window.getSelection();
var rangeObj = selectionObj.getRangeAt(0);
var docFragment = rangeObj.cloneContents();
var div = document.createElement("div");
div.appendChild(docFragment);
div.innerHTML;
document.cookie;
document.documentElement.scrollHeight || document.body.scrollHeight;
document.documentElement.scrollWidth || document.body.scrollWidth;
window.scrollTo(50,70 );
document.body.contentEditable=true;
alert("Hello");
confirm("Are you fine?");
prompt("Your cat");
window.open("http://www.nlc.cn");