-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10_index10.js
113 lines (82 loc) · 2.04 KB
/
10_index10.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
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
103
104
105
106
107
108
109
110
111
112
113
//hoisting
hello();
function hello(){
console.log("hello world");
}//output- hello world
// //this will not work in case function expression
// hello1()
// const hello1 = function(){
// console.log("hello1 world");
// }//output - error
console.log(hello);
var hello = "mishraji"; //this will not work in case of const, let
console.log(hello);
//----------------------------------------------------------------------------------------------//
//block scope vs function scope
//let and const are block scope
//var is function scope
{
var firstName= 'manish';//not working with const and let
}
console.log(firstName);
{
console.log(firstName);
}
function myApp(){
if(true){
// let happycat = " jhoom";//error
var happycat = " jhoom";
console.log(happycat);
}
console.log(happycat);
}
myApp();
//--------------------------------------------------------------------------------------------//
//default parameters
// function addTwo(a,b){
// if(typeof b ==="undefined"){ //before es2015 syntex
// b=0;
// }
// return a+b;
// }
function addTwo(a,b=0){
return a+b;
}
const ans = addTwo(4,8);
console.log(ans);
//---------------------------------------------------------//
//rest parameters
// function myFunc(a,b,...c){
// console.log(`a is ${a}`);
// console.log(`b is ${b}`);
// console.log(`c is ${c}`);
// }
// myFunc(3,4,6,7,8,99,6);
function addAll(...numbers){
// console.log(numbers);
// console.log(Array.isArray(numbers));
let total = 0;
for(let number of numbers){
total= total+ number;
}
return total;
}
const answer = addAll(1,2,3,4,5);
console.log(answer);
//parameter destructuring
//object
//react
const person ={
firstName: "Manish",
gender : "male",
}
// function printDetails(obj){
// console.log(obj.firstName);
// console.log(obj.gender);
// }
function printDetails({firstName,gender,age}){
console.log(firstName);
console.log(gender);
console.log(age);// undefined
}
printDetails(person);