Syntax Tips

https://www.notion.so/Syntax-Tips-17687191d3c04a8baa7136d0a2dec309

?? and ||

1
2
3
4
5
6
7
a || b    // equals: a ? a : b
a ?? b    // equals: a != undefined && a != null ? a : b
!''       // output: true
0 ?? 'a'  // output: 0
0 || 'a'  // output: "a"
'' ?? 'a' // output: ""
'' || 'a' // output: "a"

call, apply, bind

These methods can change the this point.

1
2
3
4
5
6
7
function test(arg1, arg2) {};

test.call(null, a1, a2);
test.apply(null, [a1, a2]);

var t = test.bind(null);
t();
This post is licensed under CC BY 4.0 by the author.