- automatically add
;
at the end - comment
//
or/* ... */
isNaN(NaN); // true
2 / 0; // Infinity
0 / 0; // NaN
1 / 3 === (1 - 2 / 3); // false
- 0 is a number, '' means empty string, null is empty value
- multiple lines string could use
`...`
var message = `Hi, ${name}, you are ${age} year old this year.`
toUpperCase
,toLowerCase
,indexOf
,substring
will NOT change the original string
indexOf
,slice
,push
,pop
,unshift
,shift
,sort
,reverse
,splice
,contac
,join
will NOT change the original string
- use
''
if property name contain special character.
var A = {
name: 'mock name',
birthday: '01\/01\/2019',
height: 6,
'high-school': 'P A High'
}
Note: Cannot use A.high-school
, use A['high-school']
// 'P A High'
hasOwnProperty()
to decide whether the this prop is owned by the object itself.
- Set only has keys, keys could not be same
for ... of
var s = new Set(['A', 'B', 'C']);
for (var x of s) {
console.log(x);
}
forEach
var s = new Set(['A', 'B', 'C']);
s.forEach(function (element, sameElement, set) {
console.log(element);
});
var m = new Map([[1, 'x'], [2, 'y'], [3, 'z']]);
m.forEach(function (value, key, map) {
console.log(value);
});
var a = ['A', 'B', 'C'];
a.forEach(function (element) {
console.log(element);
});