-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.js
50 lines (43 loc) · 858 Bytes
/
functions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Basic function
function myFunction() {
return "Hello, world!";
}
var x = myFunction();
console.log(x);
// Parameterized Function
function prod(a,b){
return a*b;
}
var x = prod(5,3);
console.log(x);
// Function Expression
const count = function(array) {
return array.length;
}
var x=[1,2,3];
console.log(count(x));
// Arrow Function
const absValue = (number) => {
if (number < 0) {
return -number;
}
return number;
}
console.log(absValue(-10));
// Generator Function
function* indexGenerator(){
var index = 0;
while(true) {
yield index++;
}
}
const g = indexGenerator();
console.log(g.next().value);
console.log(g.next().value);
// New Function
(function() {
'use strict';
const global = new Function('return this')();
console.log(global === window); // => true
console.log(this === window); // => false
})();