摘要:結(jié)果
Date Get the number of days in a month
The 0th day of next month is the last day of the current month.
function daysInMonth(year, month) { let date = new Date(year, month + 1, 0); return date.getDate(); } /** * Note that JS Date month starts with 0 * The following computes how many days in March 2017 */ console.log(daysInMonth(2017, 2)); // 31 // how many days in Feb 2017 console.log(daysInMonth(2017, 1)); // 28 // how many days in Feb 2016 console.log(daysInMonth(2016, 1)); // 29getTimezoneOffset - get the time zone difference, in minutes, from current locale (host system settings) to UTC.
let now = new Date(); console.log(now.toISOString()); //2018-03-12T01:12:29.566Z // China is UTC+08:00 console.log(now.getTimezoneOffset()); // -480 // convert to UTC let UTCDate = new Date(now.getTime() + now.getTimezoneOffset() * 60 * 1000); console.log(UTCDate.toISOString()); //2018-03-11T17:12:29.566Z //convert to UTC+03:00 let eastZone3Date = new Date(UTCDate.getTime() + 3 * 60 * 60 * 1000); console.log(eastZone3Date.toISOString()); //2018-03-11T20:12:29.566ZJSON [JSON.stringify(value[, replacer[, space]])](https://developer.mozilla.org... When replacer is a function - apply replacer before stringify the value.
JSON.stringify({ a: 4, b: [3, 5, "hello"], }, (key, val) => { if(typeof val === "number") { return val * 2; } return val; }); //{"a":8,"b":[6,10,"hello"]}when replacer is an array - use replacer as a white list to filter the keys
JSON.stringify({ a: 4, b: { a: 5, d: 6 }, c: 8 }, ["a", "b"]); //{"a":4,"b":{"a":5}}space can be used to beautify the output
JSON.stringify({ a: [3,4,5], b: "hello" }, null, "|-- "); /**結(jié)果: { |-- "a": [ |-- |-- 3, |-- |-- 4, |-- |-- 5 |-- ], |-- "b": "hello" } */String [String.prototype.split([separator[, limit]])](https://developer.mozilla.org...
"".split("") // []separator can be a regular expression!
"abc1def2ghi".split(/d/); //["abc", "def", "ghi"]
If the seperator is a regular expression that contains capturing groups, the capturing groups will appear in the result as well.
"abc1def2ghi".split(/(d)/); // ["abc", "1", "def", "2", "ghi"]Tagged string literals
let person = "Mike"; let age = 28; function myTag(strings, personExp, ageExp) { let str0 = strings[0]; // "that " let str1 = strings[1]; // " is a " // There is technically a string after // the final expression (in our example), // but it is empty (""), so disregard. // var str2 = strings[2]; let ageStr; if (ageExp > 99){ ageStr = "centenarian"; } else { ageStr = "youngster"; } return str0 + personExp + str1 + ageStr; } let output = myTag`that ${ person } is a ${ age }`; console.log(output); // that Mike is a youngsternull vs undefined
If we don"t want to distinguish null and undefined, we can use ==
undefined == undefined //true null == undefined // true 0 == undefined // false "" == undefined // false false == undefined // false
Don"t simply use == to check for the existence of a global variable as it will throw ReferenceError. Use typeof instead.
// a is not defiend under global scope a == null // ReferenceError typeof a // "undefined"Spread Operator(...)
spread operator works for objects!
const point2D = {x: 1, y: 2}; const point3D = {...point2D, z: 3}; let obj = {a: "b", c: "d", e: "f"}; let {a, ...other} = obj; console.log(a); //b console.log(other); //{c: "d", e: "f"}Reference
Speaking Javascript
MDN
NoticeIf you want to follow the latest news/articles for the series of reading notes, Please 「Watch」to Subscribe.
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://m.specialneedsforspecialkids.com/yun/93463.html
摘要: ;;;;;;;;;;;;;;;;;;; ; Module Settings ; ;;;;;;;;;;;;;;;;;;; [CLI Server] ; Whether the CLI web server uses ANSI color coding in its terminal output. cli_server.color = On [Date] ; Defines th...
Thoughts Recently I have been reading the book Async Javascript about JS asynchronicity and JS event is one of the useful solutions to the problem. To get a deeper understanding of how events work, I ...
摘要:在我們的程序中有很多變量標(biāo)識符,我們現(xiàn)在或者將來將使用它。當(dāng)我們使用時(shí),如果并沒有找到這個(gè)變量,在非嚴(yán)格模式下,程序會默認(rèn)幫我們在全局創(chuàng)建一個(gè)變量。詞法作用域也就是說,變量的作用域就是他聲明的時(shí)候的作用域。 作用域 定義 首先我們來想想作用域是用來干什么的。在我們的程序中有很多變量(標(biāo)識符identifier),我們現(xiàn)在或者將來將使用它。那么多變量,我咋知道我有沒有聲明或者定義過他呢,...
I always want imporve my skills on VIM. Thus recently I spent two days on setting up a VIM IDE for C/C++ proprogramming. Below are some useful steps for YCM. Specifications Mac InfoOS X Yosemite Versi...
閱讀 2520·2021-09-26 10:18
閱讀 3397·2021-09-22 10:02
閱讀 3196·2019-08-30 15:44
閱讀 3333·2019-08-30 15:44
閱讀 1838·2019-08-29 15:25
閱讀 2581·2019-08-26 14:04
閱讀 2047·2019-08-26 12:15
閱讀 2446·2019-08-26 11:43