1> 'abc' === 'abc'
2true
1> {x: 1, y: 4} === {x: 1, y: 4}
2false
1> #{x: 1, y: 4} === #{x: 1, y: 4}
2true
1@[ValueType]
2class Point {
3 // ···
4}
1const m = new Map();
2m.set({x: 1, y: 4}, 1);
3m.set({x: 1, y: 4}, 2);
4assert.equal(m.size, 2);
1> 2 ** 53
29007199254740992
3> (2 ** 53) + 1 // can’t be represented
49007199254740992
5> (2 ** 53) + 2
69007199254740994
1> 2n ** 53n
29007199254740992n
3> (2n ** 53n) + 1n
49007199254740993n
1const int64a = BigInt.asUintN(64, 12345n);
2const int64b = BigInt.asUintN(64, 67890n);
3const result = BigInt.asUintN(64, int64a * int64b);
1> 0.1 + 0.2
20.30000000000000004
1> 0.1m + 0.2m
20.3m
1> typeof null
2'object'
3> typeof function () {}
4'function'
5> typeof []
6'object'
第三,instanceof不适用于来自其他realm(框架等)的对象。
1// 条件表达式
2let str1 = someBool ? 'yes' : 'no';
3
4// 条件声明
5let str2;
6if (someBool) {
7 str2 = 'yes';
8} else {
9 str2 = 'no';
10}
1let str3 = do {
2 if (someBool) {
3 'yes'
4 } else {
5 'no'
6 }
7};
1const func = (() => {
2 let result; // cache
3 return () => {
4 if (result === undefined) {
5 result = someComputation();
6 }
7 return result;
8 }
9})();
1const func = do {
2 let result;
3 () => {
4 if (result === undefined) {
5 result = someComputation();
6 }
7 return result;
8 };
9};
1const resource = await fetch(jsonService);
2case (resource) {
3 when {status: 200, headers: {'Content-Length': s}} -> {
4 console.log(`size is ${s}`);
5 }
6 when {status: 404} -> {
7 console.log('JSON not found');
8 }
9 when {status} if (status >= 400) -> {
10 throw new RequestError(res);
11 }
12}
1const y = h(g(f(x)));
1const y = x |> f |> g |> h;
1f(123)
2123 |> f
1123 |> f(#)
2123 |> (x => f(x))
1import {map} from 'array-tools';
2const result = arr |> map(#, x => x * 2);
1promise
2|> await #
3|> # || throw new TypeError(
4 `Invalid value from ${promise}`)
5|> capitalize // function call
6|> # + '!'
7|> new User.Message(#)
8|> await stream.write(#)
9|> console.log // method call
10;
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |