-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic_javascript.js
191 lines (152 loc) · 4.44 KB
/
basic_javascript.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// javascript variable
// let val1 = "consistency is key" //string
// console.log(val1,typeof(val1))
// let a = 12 + 34;
// let b = 34 + "b"; //use with concadtion operator
// let c = 'c' + 7;
// console.log(a,b,c);
// hostingnpm install -g nodemon
// var val
// console.log(val);
// // undefined
// let val2var val
// console.log(val);
// // undefined
// let val2
// console.log(val2);
// const val3 Missing initializer in const declaration
// console.log(val3)
// function
// function abc(){
// console.log("this is title of the abc")
// }
// abc();
//function expression
// let abc = function(){
// console.log("this is tile of the abc but difference")
// }
// difference between function and function expression :
// hosting
// object;
const person = {
firstName: "John",
lastName: "Doe",
age: 50,
eyeColor: "blue"
};
// console.log(person,typeof(person));
// console.log(person["firstName"])
// console.log(person.firstName)
// loops
// for in
// for of
// foreach
// to use with iterable in the any variable (which is the object(string,object,array also))
// for(let k in person){
// // console.log(k); to print the key
// console.log(k,person[k])
// }
// let arr = [34,45,67,89,90]
// for(let k in arr){
// console.log(arr[k])
// }
// for of loop
// iterable object = string, array
// for (variable of iterable)
// statement
// let sum = 0;
// for(let element of arr){
// // console.log(element)
// sum += element
// }
// console.log(element);
//
// let arr = [34,45,67,89,90]
// Array
let arr = [34,45,67,89,90,56,78,90,23,45] // array which group of the variable
console.log(arr,typeof(arr)) //which is object
//Array constructor
//main point about the array that sort m
let arr1 = new Array(7) //parameter which is length
// here intialize to array size which creating 7 length but
// main things that here empty variables add
console.log(arr1)
// Array(7) [ <7 empty slots> ]
// array method
// concat method
// const array1 = ['a', 'b', 'c'];
// const array2 = ['d', 'e', 'f'];
// const array3 = array1.concat(array2);
// console.log(array3);
// entries
// const iterator1 = arr.entries();
// // return the iterator
// console.log(iterator1.next().value) //[ 0, 34 ]
// console.log(iterator1.next().value)
// filter
// const eventArr = arr.filter(e => e % 2 == 0);
// const oddArr = arr.filter(e => e % 2 !== 0);
// console.log(eventArr);
// console.log(oddArr);
// find()
const finde = arr.find(e=>e>50)
console.log(finde) //67
// flatMap()
// return array which is depth one to convert the all subarray to element
// const arr2 = [1, 2, [3], [4, 5], 6, [[[5,6,[90,[5,7,9]]]]]];
// const flatmap = arr2.flatMap(num => num);
// console.log(flatmap);
// Array.from()
// create new array shallow-copied array instance from given existence array
const charArr = Array.from("jayendra");
console.log(charArr)
//main point about the array that sort method sort the string type which lexicographic order
// ex :
let array = [567,23,12,100,34,20000,3000];
array.sort();
// console.log(array);
// Array(7) [ 100, 12, 20000, 23, 3000, 34, 567 ]
// therefore use to callback in sort method
array.sort((a,b)=> a-b);
console.log(array);
// Array(7) [ 12, 23, 34, 100, 567, 3000, 20000 ]Person.prototype.calculateAge= function(){
console.log('The current age is: '+(2019- this.yearOfBirth));
console.log(Person.prototype);
// let x = 9.656;
// x.toFixed(0);
// console.log(x);
// x.toFixed(2);
// console.log(x);
// x.toFixed(4);
// console.log(x);
// x.toFixed(6);
// console.log(x);// function constructor
function Person(name, job, yearOfBirth){
this.name= name;
this.job= job;
this.yearOfBirth= yearOfBirth;
}
// this will show Person's prototype property.
console.log(Person.prototype);
Array.prototype.calculateAge= function(){
console.log('The current age is: '+(2019- this.yearOfBirth));
}
console.log(Array.prototype);
const p1 = new Person("jayendra","do",23);
console.log(p1);
const p2 = new Person("nitin","do",45);
console.log(p2);
// function User(firstName, lastName, email, age, address){
// this.firstName = firstName;
// this.lastName = lastName;
// this.email = email;
// this.age = age;
// this.address = address;
// this.about = function(){
// return `${this.firstName} is ${this.age} years old.`;
// };
// this.is18 = function(){
// return this.age >= 18;
// }
// }
// console.log(User.prototype);