-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.js
More file actions
47 lines (32 loc) · 900 Bytes
/
functions.js
File metadata and controls
47 lines (32 loc) · 900 Bytes
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
function greet(){ //function declaration
console.log('Hello world')
}
greet() //function calling
let add = function(num1, num2){ //function expression
return num1+num2
}
let result = add(3,4)
console.log(result)
function area(r){
let pi = 3.14 //local variable
return (pi * r *r)
}
let output = area(2) //global variable
console.log(output)
let mul = (val1, val2) => { //arrow function
return val1*val2
}
let out = mul(2,3)
console.log(out)
function sub(a1,a2){ //a1 and a2 are parameters
return a1-a2
}
let val = sub(5,4) //5 and 4 are arguments
console.log(val)
function Person(name, age){
this.Name = name
this.Age = age
}
Person.prototype.nationality = 'India' //object prototype
let value = new Person('John', '8')
console.log(value.nationality)