forked from learning-zone/javascript-basics
- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunctions.html
More file actions
Latest commit
102 lines (89 loc) · 3.07 KB
/
Copy pathfunctions.html
File metadata and controls
102 lines (89 loc) · 3.07 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!DOCTYPE html>
<html>
<head>
<title>Types of functions in JavaScript</title>
</head>
<script>
// ----------------------
// Hoisting functions()
// ----------------------
varexpression=function(name){
console.log('Hi '+name);
};
expression('Pradeep');
/* *
* Curray function
*
* Currying is a process in functional programming in which we can transform a function with multiple arguments
* into a sequence of nesting functions. It returns a new function that expects the next argument inline.
*
* */
functionmultiply(a){
returnfunction(b){
returnfunction(c){
returna*b*c;
};
};
}
console.log('Curray function: '+multiply(1)(2)(3));// 6
/**
* Arrow Function()
*
* An arrow function expression is a syntactically compact alternative to a regular function expression,
* although without its own bindings to the this, arguments, super, or new.target keywords. Arrow function
* expressions are ill suited as methods, and they cannot be used as constructors.
*
* **/
varmaterials=[
'Hydrogen',
'Helium',
'Lithium',
'Beryllium'
];
console.log('Arrow Function: '+materials.map(material=>material.length));
constaddition=(x,y)=>{returnx+y};
console.log('addition: '+addition(10,20));
/**
* Constructor Function()
*
* The Function constructor creates a new Function object. Calling the constructor directly can
* create functions dynamically, but suffers from security and performance issues to eval.
* However, unlike eval, the Function constructor creates functions which
* execute in the global scope only.
*
* **/
varsum=newFunction('a','b','return a + b');
console.log('sum: '+sum(10,20));// 30
/**
* unescape() Function
*
* Note:- The unescape() function was deprecated in JavaScript version 1.5. Use decodeURI() or decodeURIComponent() instead.
*
* **/
varurl="https://www.google.co.in/?gfe_rd=cr&ei=VmKuWJ_EAcqBoAOrwZ2YDg";
varurl_esc=escape(url);
varurl_unesc=unescape(url);
console.log('escape URL: '+escape(url));
console.log('unescape URL: '+unescape(url));
/***
* Callback function()
*
* A callback is a function that is to be executed after another function has finished executing.
*
* A callback function is a function passed into another function as an argument, which is then
* invoked inside the outer function to complete some kind of routine or action.
*
***/
functiongreeting(name){
alert('Hello '+name);
}
functionprocessUserInput(callback){
varname=prompt('Please enter your name: ');
callback(name);
}
processUserInput(greeting);
</script>
<body>
<h1>Types of functions in JavaScript</h1>
</body>
</html>