1//detecting arrow key presses
2document.addEventListener('keydown', function(e) {
3 switch (e.keyCode) {
4 case 37:
5 alert('left');
6 break;
7 case 38:
8 alert('up');
9 break;
10 case 39:
11 alert('right');
12 break;
13 case 40:
14 alert('down');
15 break;
16 }
17});
1
2document.addEventListener('keydown', function(e) {
3 switch (e.keyCode) {
4 case 37:
5 alert('left');
6 break;
7 case 38:
8 alert('up');
9 break;
10 case 39:
11 alert('right');
12 break;
13 case 40:
14 alert('down');
15 break;
16 }
17});
18document.onkeydown = checkKey;
19
20function checkKey(e) {
21
22 e = e || window.event;
23
24 if (e.keyCode == '38') {
25 // up arrow
26 }
27 else if (e.keyCode == '40') {
28 // down arrow
29 }
30 else if (e.keyCode == '37') {
31 // left arrow
32 }
33 else if (e.keyCode == '39') {
34 // right arrow
35 }
36
37}
1document.onkeydown = checkKey;
2
3function checkKey(e) {
4
5 e = e || window.event;
6
7 if (e.keyCode == '38') {
8 // up arrow
9 }
10 else if (e.keyCode == '40') {
11 // down arrow
12 }
13 else if (e.keyCode == '37') {
14 // left arrow
15 }
16 else if (e.keyCode == '39') {
17 // right arrow
18 }
19
20}
1// Traditional Function Expression
2var add = function(a,b){
3 return a + b;
4}
5
6// Arrow Function Expression
7var arrowAdd = (a,b) => a + b;
8