1//No currying
2function volume(w, h, l) {
3 return w * h * l;
4}
5
6volume(4, 6, 3); // 72
7
8//Currying
9function volume(w) {
10 return function(h) {
11 return function(l) {
12 return w * h* l;
13 }
14 }
15}
16
17volume(4)(6)(3); // 72
1function func() {
2 this.var = 5;
3
4 this.changeVar = function() {
5 setTimeout(() => { //Don't use function, use arrow function so 'this' refers to 'func' and not window
6 this.var = 10;
7 }, 1000);
8 }
9}
10
11var a = new func();
12a.changeVar();
1console.log ('Starting');
2let image;
3
4fetch('coffee.jpg').then((response) => {
5 console.log('It worked :)')
6 return response.blob();
7}).then((myBlob) => {
8 let objectURL = URL.createObjectURL(myBlob);
9 image = document.createElement('img');
10 image.src = objectURL;
11 document.body.appendChild(image);
12}).catch((error) => {
13 console.log('There has been a problem with your fetch operation: ' + error.message);
14});
15
16console.log ('All done!');
1const printProcess = () => {
2 console.log('it will print 2nd');
3 var currentTime = new Date().getTime();
4 while (currentTime + 3000 >= new Date().getTime());
5 console.log('it will print after added 3 second with current time')
6}
7
8console.log('it will print 1st ');
9printProcess(); //follow arrow funtion after 1st print
10console.log('it will print at the end');
11//Expected output below:
12// it will print 1st
13// it will print 2nd
14// it will print after added 3 second with current time
15// it will print at the end
1//Asynchronous JavaScript
2console.log('I am first');
3setTimeout(() => {
4 console.log('I am second')
5}, 2000)
6setTimeout(() => {
7 console.log('I am third')
8}, 1000)
9console.log('I am fourth')
10//Expected output:
11// I am first
12// I am fourth
13// I am third
14// I am second
1//Asynchronous JavaScript
2console.log('I am first');
3setTimeout(() => {
4 console.log('I am second')
5}, 2000)
6setTimeout(() => {
7 console.log('I am third')
8}, 1000)
9console.log('I am fourth')
10//Expected output:
11// I am first
12// I am fourth
13// I am third
14// I am second